Skip to content
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

Make type.Name/type.FullName work in reflection free mode #1019

Closed
davidfowl opened this issue Apr 26, 2021 · 3 comments
Closed

Make type.Name/type.FullName work in reflection free mode #1019

davidfowl opened this issue Apr 26, 2021 · 3 comments
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Comments

@davidfowl
Copy link
Member

Maybe this isn't possible (and I haven't dug in) but is it possible to make type.Name/type.FullName work with reflection free mode (which I know is basically impossible to make certain workloads work). There are a bunch of scenarios where knowing the type name is important (not just for logging) but for error messages etc.

If that wasn't possible the other crazy idea I had was to support it only for generic methods:

Something<T> GetSomething<T>()
{
    return new Something<T>(typeof(T).FullName);
}

var something = Something<MyType>();

The AOT compiler could replace this with a constant generated at compile time.

Something<MyType> GetSomething<MyType>()
{
    return new Something<T>("Namespace.MyType");
}
@MichalStrehovsky MichalStrehovsky added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Apr 26, 2021
@MichalStrehovsky
Copy link
Member

Yup, these are the "Reflection APIs that are up for discussion".

For that to be feasible, we should ideally get rid of System.Private.DisabledReflection and replace it with the real reflection stack where we disable certain codepaths using the .NET 5 feature switches. I don't want to replicate metadata parsing and resolution in System.Private.DisabledReflection.

@josephmoresena
Copy link

typeof(T).ToString() is weird but works and that is really a blessing. If you controlls the code you could manual and maintainable (contradictious?) code which combines typeof(T).ToString() with nameof(class) and static code.

@jkotas
Copy link
Member

jkotas commented Jul 15, 2021

Duplicate of dotnet/runtime#67193

@jkotas jkotas closed this as completed Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

No branches or pull requests

4 participants