473,406 Members | 2,387 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.

Reading objects attributes of an Arraylist

ree
I have an arraylist and I want to read attributes of the object in it. But
with C++ using vectors its was straight forward. But I am lost with
arraylists as these can hold variety of objects.
Nov 16 '05 #1
3 3532
If you use the logic in this example
http://www.knowdotnet.com/articles/reflectionmore.html you can just
substitute the hard coded object names for the values in your arraylist.
You can use the GetAttributes method (I didn't mention it explicitly). This
should help fill in the gaps
http://msdn.microsoft.com/msdnmag/issues/01/10/net/

HTH,

Bill

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"ree" <re*@hotmail.coom> wrote in message
news:Xn***************************@211.29.133.50.. .
I have an arraylist and I want to read attributes of the object in it. But
with C++ using vectors its was straight forward. But I am lost with
arraylists as these can hold variety of objects.

Nov 16 '05 #2
Hi ree,

Yes, an ArrayList will return objects so you need to cast the object back to it's original class or one of it's "parents" or interfaces to be able to access any properties.

You can test if an object can be cast to a class like this

object obj = list[0];

if(obj is MyClass)

And get the real type of the object with

Type t = obj.GetType();

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Ah, upon rereading, I reliazed you asked about attributes, not properties.
You can try using the Type's Attributes property. Not exactly sure how to use it, but testing it on a string and converting the TypeAttribute using ToString() gave me

AutoLayout, AnsiClass, NotPublic, Public, Sealed, Serializable, BeforeFieldInit

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4

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

Similar topics

0
by: vanGogh | last post by:
I have generated classes based on an Xml schema file (xsd) using the XSD.exe tool. My goal is to: - write an application that can parse XML documents - fill objects (based on the generated...
1
by: davis | last post by:
Hello, I am working in .Net C# and have an xml file similar to the one below. I have tried using a DataSet but get the error "The same table (Gid) cannot be the child table in two nested...
10
by: Arjen | last post by:
Hello, I still don't get it! Let's say that we have some persons.... some persons have a car. The objects that we have are "person" and "car". "Person" -- Create person -- Haves car
2
by: ree | last post by:
I am new to C# in C++ you can use vectors to handle a unknown quantity of set of objects. But in C# not sure what to use. As I tried arraylists but they can hold a variety of objects. So...
5
by: Alex Nitulescu | last post by:
Hi. I'm fighting the following code: __________________________________________________________________________ a. I have a class UserInfo.vb: <Serializable()> Public Class UserInfo Public...
5
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete...
4
by: sherifffruitfly | last post by:
Hi, I have an xml file with structured like this: <?xml version="1.0" encoding="UTF-8"?> <Soldiers> <Soldier name="Billy Smith" rank="Private" serial="34" /> (a bunch more soldiers)
2
by: =?Utf-8?B?RHJldw==?= | last post by:
I have a current requirement to all a subsidiary to use a current legacy application and interface with my new system to inject data when appropriate. I wanted to create a web service since we are...
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
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:
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
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
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...
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...

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.