Reputation: 1
I'm trying to work with two contexts in a generic repository and I should invoke the static method GetObjectContext()
with dynamic type like ObjectContextManager<DynamicType>.GetObjectContext()
.
private DataContext GetDataContext()
{
Type type = GetContainerType();
Type paoloGenericClassType = typeof(ObjectContextManager<>).MakeGenericType(type);
MethodInfo method = paoloGenericClassType.GetMethod("GetObjectContext", BindingFlags.Static);
return method.Invoke(null, BindingFlags.Static, null, null, null) as DataContext;
}
I'm try different variants, but it doesn't work. How can I do this?
Upvotes: 0
Views: 172
Reputation:
Checkout this article on how to invoke generic methods via reflection.
DaTribe
Upvotes: 0
Reputation: 1500625
I suspect the problem is just with your binding flags. Try BindingFlags.Static | BindingFlags.Public
, assuming it's a public method.
If that doesn't work, please tell us what actually happens, rather than just saying it doesn't work.
Upvotes: 1