Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to GetMethod that use Dynamic Parameter (TypeParam)?

How to GetMethod that use Dynamic Parameter (TypeParam)?

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    f3rland
    wrote on last edited by
    #1

    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!!!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups