c# Programming Glossary: makegenericmethod
How do I invoke an extension method using reflection? http://stackoverflow.com/questions/1452261/how-do-i-invoke-an-extension-method-using-reflection the method you must make the methodinfo specific using the MakeGenericMethod call. Here is a full working sample using System using System.Collections.Generic.. we need to specialize it whereMethod whereMethod.MakeGenericMethod typeof MyObject var ret whereMethod.Invoke myObjects new object..
Reflection and generic types http://stackoverflow.com/questions/196936/reflection-and-generic-types In which case as is you would need to use reflection and MakeGenericMethod i.e. var properties this.GetType .GetProperties foreach PropertyInfo.. properties object value typeof MyClass .GetMethod DoStuff .MakeGenericMethod p.PropertyType .Invoke null new object p.Name p.SetValue this..
How to use reflection to call generic Method? http://stackoverflow.com/questions/232535/how-to-use-reflection-to-call-generic-method with then construct it by supplying type arguments with MakeGenericMethod MethodInfo method typeof Sample .GetMethod GenericMethod MethodInfo.. Sample .GetMethod GenericMethod MethodInfo generic method.MakeGenericMethod myType generic.Invoke this null EDIT For a static method pass..
Calling generic method with a type argument known only at execution time http://stackoverflow.com/questions/325156/calling-generic-method-with-a-type-argument-known-only-at-execution-time generic method with Type.GetMethod Make it generic using MakeGenericMethod Invoke it with Invoke Here's some sample code. Note that I changed.. Type type in types MethodInfo genericMethod method.MakeGenericMethod new Type type genericMethod.Invoke null null No target no arguments.. got to use generics. Get the generic method and call MakeGenericMethod on it then invoke it. Is your interface type itself actually..
Deserialize unknown type with protobuf-net http://stackoverflow.com/questions/675349/deserialize-unknown-type-with-protobuf-net method typeof ProtoBuf.Serializer .GetMethod Deserialize .MakeGenericMethod t message method.Invoke null new object ms as Messages.BaseMessage.. which handle length for you optionally with a tag . The MakeGenericMethod looks OK at first glance and this actually ties in very closely..
DynamicMethod with generic type parameters http://stackoverflow.com/questions/788618/dynamicmethod-with-generic-type-parameters has no DefineGenericParameters method and it inherits MakeGenericMethod from its MethodInfo base class which just throws NotSupportedException..
|