Begin PART 1 : I have a sub
Private Sub PrintProperties(Of T)(ByVal pItem As T)
[...]
End Sub
that I need to access it through MethodInfo :
Private Sub PrintPropertiesMaster(Of T)()
[...]
Dim method As MethodInfo = GetType(Form1).GetMethod("PrintProperties", _
(System.Reflection.BindingFlags.Instance _
Or (System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.NonPublic)), _
Nothing, New Type() {GetType(T)}, Nothing)
[...]
End Sub
but method
is set to nothing after the previous line. :confused: I'm sure I miss something in the Type.GetMethod parameters. Any idea? End PART 1 Begin PART 2 : Another way to achieve my goal could be to know how to specify a TypeParam dynamically. Let me explain this with sample : This is my not conforming code:
For Each oEnt As Entity In DefaultManager.GetEntities(Of SomeNameSpace.ObjOne)()
PrintProperties(Of SomeNameSpace.ObjOneDataRow)(CType(oEnt, SomeNameSpace.ObjOneDataRow))
Next
For Each oEnt As Entity In DefaultManager.GetEntities(Of SomeNameSpace.ObjTwo)()
PrintProperties(Of SomeNameSpace.ObjTwoDataRow)(CType(oEnt, SomeNameSpace.ObjTwoDataRow))
Next
'And so on
[...]
I need to access it using a System.Type instead of TypeParam (Of Something
) (Consider that ObjOne Inherits from ObjOneDataRow and ObjTwo Inherits from ObjTwoDataRow. In other words, ObjOneDataRow is the base class of ObjOne) So one parameter should be enough to know all the needed System.Type to finish with something like this :
Private Sub PrintValues(Of T)()
For Each oEnt As Entity In DefaultManager.GetEntities(Of T)()
PrintProperties(Of GetType(T).BaseType)(CType(oEnt, GetType(T).BaseType))
Next
End Sub
but this does not compile :( End PART 2 Thanks for any help!!!