473,398 Members | 2,403 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,398 software developers and data experts.

Reflecting a Structure

I created a structure with several variables in it.

I wanted to add all the variables of the structure into a listbox. Is there
a way I can do this in some kind of loop rather than having to type in 26
item.add lines. How does the Intellisence figure out and list out the
variables?

Thanks
Brent
Nov 21 '05 #1
2 938

"Brent" <Br***@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
I created a structure with several variables in it.

I wanted to add all the variables of the structure into a listbox. Is
there
a way I can do this in some kind of loop rather than having to type in 26
item.add lines. How does the Intellisence figure out and list out the
variables?

Thanks
Brent


Dim st As MyStruct
Dim tp As System.Type = st.GetType()
Dim s As String

Console.WriteLine("Definition: " & tp.Name & " - " & tp.ToString())
Console.WriteLine("Members")
Console.WriteLine("-------")

For Each fi As Reflection.FieldInfo In tp.GetFields()
Console.WriteLine(Space(4) & fi.Name & " As " &
fi.MemberType.ToString())
Next

Console.WriteLine()

Console.WriteLine("Methods")
Console.WriteLine("-------")

For Each fi As Reflection.MethodInfo In tp.GetMethods()
Console.WriteLine(Space(4) & fi.Name)
Next
Nov 21 '05 #2
Thanks, that works.
I have to ask a follow up question. I thought I could use fi.setvalue to
update an item's value, but it doesn't work.

fi = tp.GetField(Item)
MsgBox(fi.GetValue(InItems)) 'returns the original value
fi.SetValue(InItems, Value.ToString) 'Nothing happens
MsgBox(fi.GetValue(InItems)) 'still returns the original
value

What am I missing here? Is this the right way to do it?

Thanks
Brent


"Mythran" wrote:

"Brent" <Br***@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
I created a structure with several variables in it.

I wanted to add all the variables of the structure into a listbox. Is
there
a way I can do this in some kind of loop rather than having to type in 26
item.add lines. How does the Intellisence figure out and list out the
variables?

Thanks
Brent


Dim st As MyStruct
Dim tp As System.Type = st.GetType()
Dim s As String

Console.WriteLine("Definition: " & tp.Name & " - " & tp.ToString())
Console.WriteLine("Members")
Console.WriteLine("-------")

For Each fi As Reflection.FieldInfo In tp.GetFields()
Console.WriteLine(Space(4) & fi.Name & " As " &
fi.MemberType.ToString())
Next

Console.WriteLine()

Console.WriteLine("Methods")
Console.WriteLine("-------")

For Each fi As Reflection.MethodInfo In tp.GetMethods()
Console.WriteLine(Space(4) & fi.Name)
Next

Nov 21 '05 #3

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

Similar topics

0
by: San | last post by:
Hello, I have DataSet which has a table named bills . I'm filling this bills table from another class named Class2 which also has the bills table with same schema. After copying the data from...
0
by: DotNetJunkies User | last post by:
I have to deserialize an XML document to objects and then serialize it back to XML to pass to the stored proc. I am attaching partial code. After this , I also have to serialize Here is the XML :...
0
by: Dave Veeneman | last post by:
I'm using XML Serialization on a class hierarchy headed by a Project Class. When I attempt to serialize, I get an InvalidOperationException from system.xml.dll with the explanation that there was...
1
by: Q. John Chen | last post by:
E.G. class ABC { // CAN ONLY HAVE ONE OF the FOLLOWING ATTRIBUTES public string Prefix = null;
3
by: Steven.Dahlin | last post by:
I have a situation where the htmlcontrols are not reflecting changes made to the textboxes when the page is returned to the server. I have a set of textboxes configured like so: <input...
3
by: The Developer | last post by:
Hi All, I have a web application where I am adding a custom attribute to my ASP.NET text box control and changing value of that attribute at client side using JavaScript. My problem is that...
4
by: MattBell | last post by:
I've tried to search for an answer to this without much success, and I think it's probably a common thing to do: I have a web service I want to accept an XmlDocument as an argument which conforms...
3
by: | last post by:
Hi all, I have a question on reflection Lets say I have a custom object called Address. Now, lets say I have a string variable that holds the name of a variable in the object such as...
24
by: ManjunathRatakonda | last post by:
Hi, Am assigning the innerHTML of a div to another div, the problem is that the assigned innerHTML is not reflected when i display the second div to which i have assigned the innerHTML of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
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...
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.