Passing Value Type Parameter in the Reflection

  • Thread starter Thread starter Elan Dro
  • Start date Start date
E

Elan Dro

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(“GUIDField”).SetValue(Obj, New
GUID(GUID.NewGUID().ToString()))
 
Elan Dro said:
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("GUIDField").SetValue(Obj, New
GUID(GUID.NewGUID().ToString()))

What's the problem? The code works. However, could be shortened to

Obj.GetType().GetField("GUIDField").SetValue(Obj, Guid.NewGuid())


Armin
 
Steve Gerrard said:
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
 
Back
Top