i have this two classes:
Item<T> : BusinessBase<T> where T : Item<T>
{
public static T NewItem()
{
//some code here
}
}
Video : Item <Video>
{
}
now i want to invoke NewItem() method on class Video using reflection. when i try with this:
MethodInfo inf = typeof(Video).GetMethod("NewItem", BindingFlags.Static);
the object inf after executing this line still is null. can i invoke static NewItem() method on class Video?
You need to specifiy BindingFlags.Public and BindingFlags.FlattenHierarchy in addition to BindingFlags.Static:
Alternatively, you can get the method from the declaring type without BindingFlags.FlattenHierarchy:
I've tried both ways and they both work.