Hi,
I need to be able to manipulate field values within a structure using
FieldInfo.GetVa lue and FieldInfo.SetVa lue, in VB.Nt 2003. The GetValue
is working fine and makes it really easy for me to maintain my code.
Unfortunately, SetValue doesn't return any errors but doesn't actually
set the value.
I have read through various newsgroup postings, and think the problem
might have something to do with "boxing", and passing of structures by
reference instead of by value. As such, I think I might be modifying a
copy of the structure, not the original structure itself. Even more
strange is that during my attempts to make it work, I found I could
issue a SetValue command within the Command Window in the VB.Net IDE
(and it would work), but the same code placed in the program did not
work. I suspect this is also to do with copies of the structure
instead of the original.
Anyway, the code below doesn't return any errors, but also doesn't set
the value! Please can somebody help me? I don't want to have to
redesign the code, and getting this working would make it really
efficient and easy to maintain
Thanks in advance
Laurie
Module module1
Structure ConfigVariables
Dim FirstVar As String
Dim SecondVar As String
Dim ThirdVar As String
End Structure
Sub Main()
Dim fld As System.Reflecti on.FieldInfo
Dim myType As Type = GetType(ConfigV ariables)
Dim myFields As System.Reflecti on.FieldInfo() = myType.GetField s()
For Each fld In myFields
fld.SetValue(CV , "Test Value")
Next fld
End Sub 3 3099
Have tried various other ways to resolve this, but still to no avail.
Has anyone got any ideas? Thanks, Laurie
Have tried various other ways to resolve this, but still to no avail.
Has anyone got any ideas? Thanks, Laurie
Managed to answer my own question after reading some advice from Jay
at http://thedotnet.com/howto/work325581.aspx
The answer is to:
Dim cv1 As ValueType = CV
<then perform all SetValue operations on the cv1 object>
CV = cv1
....Sorted!!!
Thanks Jay
Laurie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James Hadwen |
last post by:
Hi,
I'm trying to do something with reflection that's a little wierd. The idea
is that I call for a field to be updated on a base class. Using reflection
it first updates the value, and then updates the change that has been made
to a dictionary. The code below is just to encourage some ideas, if you look
at most of the code you find that most of it is pretty pointless. I might as
well have Translate(string fieldname, ref string...
|
by: Glen |
last post by:
FieldInfo.SetValue() doesn't appear to work when trying to set the values of fields of a struct. Why? Because structs are passed by value and not reference?
--
Thanks,
Glen
|
by: ORC |
last post by:
I will use FieldInfo to import values from a XML file into the fields of an
objects. But how to convert to the proper type like in this:
public void Load(object MyClass)
{
foreach( FieldInfo field in MyClass.GetType().GetFields() )
{
field.SetValue(MyClass,
String_From_XML_Representing_The_Field_Value);
}
|
by: Brent |
last post by:
I have variables in a structure loaded into a list box.
I thought I could use FieldInfo.SetValue to update the items value when the
user clicks on it, but it is not working.
..
..
..
Dim fi As Reflection.FieldInfo
fi = tp.GetField(Item)
MsgBox(fi.GetValue(InItems)) 'returns the original value
|
by: Dennis |
last post by:
I have an array "t" where each element is a structure of type "testing". I
want to use the FieldInfo class to set the values of the array element
fields. I can read the field properties and return the velue using this
technique but cannot set the field value as per below.
Why won't it change the value. If define "testing" as a class where col1
and col2 are fields as opposed to properties, it works fine. Just won't work
when "testing"...
| |
by: jw56578 |
last post by:
Im trying to use FieldInfo.SetValue to set the values of fields in a
class, the class is using reflection on itself to popluate its own
fields. but i keep getting this error.
Object type cannot be converted to target type
here is code
Dim myFieldInfo() As System.Reflection.FieldInfo
Dim myType As Type = Me.GetType
' Get the type and fields of FieldInfoClass.
|
by: David Gouge |
last post by:
Posting on behalf of a colleague (no, really! ;) )...
Hi,
I was wondering if there is any equivalent of FieldInfo.SetValue(Object,
Object) that is strongly typed or uses generics? I have been looking at
the source for FieldInfo to see if I could implement my own generic
version of this method but unfortunately the code seems to be hidden, is
there anyway I can implement my own method if there is no equivalent?
|
by: kernell |
last post by:
Hi everyone,
i'm trying to initialize all control of a UserControl to is appropriate class. The value is set but the event won't raise anymore. See the example:
'Not working
'Normally WithEvents should raise the event but nothing happen
Public Class Process
Inherits SkinProcess
|
by: damiensawyer |
last post by:
Hi,
I need to invoke .getvalue and .setvalue on fieldinfo and propetyinfo
objects. Even though they're both derived from MemberInfo, they don't
share those two methods. I've finding myself writing the following
types of structure over and over. Is there something I'm missing? Or
some 'funky' 3.5 delegate/lambda expression way of doing this?
Thanks very much in advance,
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |