Passing Value Type Parameter in the Reflection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Elan Dro

    Passing Value Type Parameter in the Reflection

    How we can pass the structure type (GUID) as value parameter to the
    object using reflection setValue method of FieldInfo, PropertyInfo and
    etc

    Ex :
    Public Class A
    Public GUIDField as GUID
    End Class
    ...
    ...
    ...
    ‘ my reflection code here
    Dim Obj as New A()
    Obj.GetType().G etField(“GUIDFi eld”).SetValue( Obj, New
    GUID(GUID.NewGU ID().ToString() ))



    *** Sent via Developersdex http://www.developersdex.com ***
  • Armin Zingler

    #2
    Re: Passing Value Type Parameter in the Reflection

    "Elan Dro" <snelankathir@h otmail.comschri eb
    How we can pass the structure type (GUID) as value parameter to the
    object using reflection setValue method of FieldInfo, PropertyInfo
    and etc
    >
    Ex :
    Public Class A
    Public GUIDField as GUID
    End Class
    ..
    ..
    ..
    ' my reflection code here
    Dim Obj as New A()
    Obj.GetType().G etField("GUIDFi eld").SetValue( Obj, New
    GUID(GUID.NewGU ID().ToString() ))
    What's the problem? The code works. However, could be shortened to

    Obj.GetType().G etField("GUIDFi eld").SetValue( Obj, Guid.NewGuid())


    Armin

    Comment

    • Steve Gerrard

      #3
      Re: Passing Value Type Parameter in the Reflection

      Armin Zingler wrote:
      "Elan Dro" <snelankathir@h otmail.comschri eb
      >How we can pass the structure type (GUID) as value parameter to the
      >object using reflection setValue method of FieldInfo, PropertyInfo
      >and etc
      >>
      >Ex :
      >Public Class A
      >Public GUIDField as GUID
      >End Class
      >..
      >' my reflection code here
      >Dim Obj as New A()
      >Obj.GetType(). GetField("GUIDF ield").SetValue (Obj, New
      >GUID(GUID.NewG UID().ToString( )))
      >
      What's the problem? The code works. However, could be shortened to
      >
      Obj.GetType().G etField("GUIDFi eld").SetValue( Obj, Guid.NewGuid())
      >
      Is there some reason not to just write
      Obj.GUIDField = Guid.NewGuid()
      directly?


      Comment

      • Armin Zingler

        #4
        Re: Passing Value Type Parameter in the Reflection

        "Steve Gerrard" <mynamehere@com cast.netschrieb
        Is there some reason not to just write
        Obj.GUIDField = Guid.NewGuid()
        directly?
        Would have been my question too, but not everytime I wonder why somebody
        needs it, and I thought it was only an example, not the real code.


        Armin

        Comment

        Working...