Reflection: Easier reflection for known members #4627
-
There are still no better way in C# for doing reflection for known Public members than the usual methods found among the API. static readonly MethodInfo MyMethod = reflect(Enumerable.Average(IEnumerable<decimal>));
static readonly MethodInfo MyMethod = reflect(Enumerable.Average(IEnumerable<object>)); // Compile time error as it doesn't exist
static readonly PropertyInfo MyProperty = reflect(MyType.MyProperty); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This has been discussed previously at #712 See also this blog post about why it's never gained much traction: https://docs.microsoft.com/en-gb/archive/blogs/ericlippert/in-foof-we-trust-a-dialogue |
Beta Was this translation helpful? Give feedback.
-
This is something that can be provided by tooling. For example an analyzer could inspect the use of reflection APIs and compare it to the types being reflected and provide warnings. IntelliJ does this with Java, for instance: |
Beta Was this translation helpful? Give feedback.
This has been discussed previously at #712
See also this blog post about why it's never gained much traction: https://docs.microsoft.com/en-gb/archive/blogs/ericlippert/in-foof-we-trust-a-dialogue