-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile time constant some reflection values #10972
Comments
Duplicate of dotnet/coreclr#2591 (though it doesn't explicitly mention |
@benaadams Do you really mean "compile-time constant" in the language sense (i.e. could be using in a switch case expression), or do you mean you want more efficient generated code? |
@gafter literally a compile time constant for the string values in the style of So More complex reflected items like bindings or assembly name I don't think would be able to be resolved at compile time as they may change as dlls were swapped or updated. A corner case would be |
So this is actually a language change request, as whether or not a string is a constant is visible to the language. |
Not sure; currently they are evaluated at runtime? Common use cases are in diagnostics and exceptions+logging which are slow areas anyway. Not hugely fussed about them working in |
Or could be an extension to |
|
@paulomorgado that would work. Rather than going
You could go
or Rather than |
😄 |
Basically, most of properties coming out of What I really want to see is the ability to do some computation on these values (read pure functions) and they still remain compile-time constants. |
@benaadams May you move this to csharplang repo? |
I like it, and I am working on a use case where that might be interesting. i.e. namespace Foo
{
class Bar { }
}
// ...
const string barNameSpace = namespaceof(Bar); // "Foo" const string |
Closing this out. We're doing all language design now at dotnet/csharplang. If you're still interested in this idea let us know and we can migrate this over to a discussion in that repo. Thanks! |
This is now proposed at dotnet/csharplang#8505. |
For example
typeof(MyClass).Namespace
could be an interned string?The text was updated successfully, but these errors were encountered: