Passing Value Type Parameter in the Reflection

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()))
 
A

Armin Zingler

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
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top