-
-
Notifications
You must be signed in to change notification settings - Fork 89
Closed
Description
Description
MakeGenericMethod
I need to call a generic function with a type decided at runtime, the only way to do this in c# is to use MakeGenericMethod with a type.
*.Where()
I often need a list of all methods that implement a certain interface and to do this it is very convenient to use .where instead of looping through all of the classes manually.
How to solve the problem
MakeGenericMethod()
MakeGenericMethod needs an implementation.
*.Where()
the IEnumerable interface needs a Where method
Describe alternatives you've considered
MakeGenericMethod
I believe that there are no alternatives to this function in the c# standard library
*.Where()
You can manually loop through all the items in the list and filter them that way.
Aditional context
example MakeGenericMethod use:
MethodInfo method = typeof(Sample).GetMethod(nameof(Sample.GenericMethod));
MethodInfo generic = method.MakeGenericMethod(myType);
generic.Invoke(this, null);example *.where use:
var typesImplementingInterface = typeof(Program).Assembly.Types.GetEnumerable.Where(t => t.IsSubClassOf(IexampleInterface));Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels