Replies: 43 comments 156 replies
-
|
If we do this, In other words, it should return what you type in C# to refer to the object, not the CLR representation. |
Beta Was this translation helpful? Give feedback.
-
|
I feel uneasy promoting my own framework here, but I made something for this a long time ago. It isn't perfect, but it will handle many common cases. You can call: And get "myVariable.MyList[i].MyProperty" out. It won't cover full type names, though. I had something for that too, but I never ported it to my current code base. https://github.com/jjvanzon/JJ.Framework/blob/master/Framework/Reflection/ExpressionHelper.cs |
Beta Was this translation helpful? Give feedback.
-
|
@janjoostvanzon That's really cool! Now if only it was a compile-time constant and could be used in an attribute... |
Beta Was this translation helpful? Give feedback.
-
|
@jnm2 That's what I thought when I made it. That would give better performance, even though I did try to make it perform well without sacrificing reliability. Still it cannot be faster than a literal string. |
Beta Was this translation helpful? Give feedback.
-
|
There is a proposal to make Also #522 suggests to add a shorthand for |
Beta Was this translation helpful? Give feedback.
-
|
@alrz not really as it would be nice to be able to refer to sub-namespaces and members as well (yes, I remember dotnet/roslyn#1653). I am mostly after shortest possible syntax but compile-time evaluation is also important. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
This stuff is ridiculous, an extra keyword just for something small like this? just add a method like Class.fullnameof |
Beta Was this translation helpful? Give feedback.
-
|
The point of it being a keyword is that it could be used as a constant. Invoking a method on the I believe there is a separate proposal for having the compiler consider certain expressions on |
Beta Was this translation helpful? Give feedback.
-
|
ok but this really sounds more like a problem about c# attributes. Why else require all these new keywords |
Beta Was this translation helpful? Give feedback.
-
|
The arguments used in attributes are required to be constants and embeddable directly in the assembly metadata. That is a limitation of the CLR and not specifically of the C# language. When the CLR actually instantiates the attribute it expects that the embedded constant matches the type of the constructor parameter or property so the C# compiler can't embed any alternatives, let alone something that represents an expression to be evaluated at runtime. The best the C# compiler could do is to introduce a form of constant expressions ( |
Beta Was this translation helpful? Give feedback.
-
|
This would be mighty convenient in some cases, especially when defining an I'm currently doing this: // I'm repeating the full namespace in each case, even though I don't strictly need to, for better safety if/when refactoring moves things around.
[EventSource(Name =
nameof(Company) + "." +
nameof(Company.ProductUmbrella) + "." +
nameof(Company.ProductUmbrella.Product) + "." +
nameof(Company.ProductUmbrella.Product.Feature) + "." +
nameof(Company.ProductUmbrella.Product.Feature.Module) + "." +
nameof(Company.ProductUmbrella.Product.Feature.Module.ETWEventSource))]
public class ETWEventSource : EventSource
{I'd be delighted to be able to do this: [EventSource(Name = fullnameof(ETWEventSource))]
public class ETWEventSource : EventSource
{ |
Beta Was this translation helpful? Give feedback.
-
|
This should work for namespaces too! I.e. |
Beta Was this translation helpful? Give feedback.
-
How does this work with generics? |
Beta Was this translation helpful? Give feedback.
-
|
This would be most usable in Obsolete attribute. |
Beta Was this translation helpful? Give feedback.
-
|
Why not reuse the current operator we already have? |
Beta Was this translation helpful? Give feedback.
-
|
Over seven years later and another basic language ask that is still not implemented, I'm sure the team will as usual justify it with "not enough interest" as they usually do for things that in reality they CBA to work on. Meanwhile Mapperly, and I imagine other projects, are coming up with their own implementations to cover for the lack of this simple yet important feature... I can guarantee that different projects will choose different ways of doing this and we'll end up with a fragmented ecosystem for no good reason. If you don't want to implement this feature, how 'bout you hire some people who do? It's not as if you're working for a scrappy startup that can't afford to hire developers. |
Beta Was this translation helpful? Give feedback.
-
|
I'm proposing making It would be great to hear in that thread about real-world use cases that support doing this, as well as real-world use cases for Spoiler: rejected! |
Beta Was this translation helpful? Give feedback.
-
|
This is a late reply giving more support to this proposition. I'm getting tired of writing long and complicated messages for my development like However this also raises a problem, which is to what extent the name is written out. Like in my use case, I don't want the namespace, only the class. An earlier comment suggested |
Beta Was this translation helpful? Give feedback.
-
|
I've found this: Perhaps |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
There are a lot of custom cases mentioned here, some with specialized handling such as wanting part of the namespace relative to another namespace. If MyFormat(infoof(SomeMember))Similar to how, today, you can already do: MyFormat(typeof(SomeType))This doesn't work in constant contexts, but it could be combined with a proposal to allow interceptors to intercept with a constant declaration instead of intercepting with a static method declaration. The compiler could then consider the intercepted expression to be constant. To make this more palatable and have better errors as a language feature, a sigil such as A downside would be that |
Beta Was this translation helpful? Give feedback.
-
|
I'm in full support of this feature, would love to have something like this built into the language. I wanted to bring visibility to Mapperly library, specifically their version of "Full It doesn't introduce any additional keywords, but just requires The related logic seems to start here in their implementation. So for full name, as their example shows, you would write: |
Beta Was this translation helpful? Give feedback.
-
|
For this to have any viable future, someone (either community or ldm) needs ot actually spec out what the proposed lang feature is and what semantics it actually has. I have just read through the entire thread (for the nth time) and it is strikign that this just isn't done anywhere. Effectively, people are asking for a If this stands a chance of succeeding, this work needs to be done. It's not a syntax question. It's a question of semantics, and producing something reasonable, effective, and consistent. |
Beta Was this translation helpful? Give feedback.
-
@CyrusNajmabadi I didn't realize this was a thing that community members had authority to do lol. Do you basically mean that somebody needs to create a document under the |
Beta Was this translation helpful? Give feedback.
-
|
For the sake of discussion, let's propose the following It supports exactly the types and members that
Because of these rules, a full name identifies a type declaration or member declaration. It does not carry context relevant to the usage of the type, such as What scenarios are well served by this description? What scenarios aren't? Examples
|
Beta Was this translation helpful? Give feedback.
-
|
Plan B:
The current design being considered is that any name that is valid in However, although
|
Beta Was this translation helpful? Give feedback.
-
|
roughly spec-ed.
|
Beta Was this translation helpful? Give feedback.
-
|
So far, in just the last few days there have been requests for:
There also appear to be entirely different views across teh board on how things like aliases, qualification, nesting, generics, tuples, arrays, pointers and so on, would be supported. This is not something a realistic specification can be made from. THe use cases are MASSIVELY different, as are the expectations from one dev to the next. The only viable options i could see are:
|
Beta Was this translation helpful? Give feedback.
-
|
After reading many comment request similar feature as new keyword. I think this kind of request will eventually unavoidably became bloated What we actually want is ability of compiler to specified
This direction also compliment const expression |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Migrated from: dotnet/roslyn#14474 and dotnet/roslyn#7973
A well-know one, not much to add.
Doing this currently which is not amazing:
Beta Was this translation helpful? Give feedback.
All reactions