473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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().GetField(“GUIDField”).SetValue(Obj, New
GUID(GUID.NewGUID().ToString()))

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
3 1345
"Elan Dro" <sn**********@hotmail.comschrieb
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
Jun 27 '08 #2
Armin Zingler wrote:
"Elan Dro" <sn**********@hotmail.comschrieb
>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(Ob j, 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())
Is there some reason not to just write
Obj.GUIDField = Guid.NewGuid()
directly?
Jun 27 '08 #3
"Steve Gerrard" <my********@comcast.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

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Robert Lario | last post by:
For examples sake I have made up a very simple example. I have an object called foo1 which is of type foo. I want to be able to call a funtion called myfunc as follows: myfunc(ref foo1) ...
6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
1
by: Néstor Sánchez A. | last post by:
Hi, is there a way, maybe using reflection, to use a generic class passing the type parameter dynamicly (not kwnowing the exact type at compile time)? I tried the next example, but doesn't work: ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.