473,624 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reflection, access the field of object dynamically

Hi,

Let say I have an instance of class, eg. ArrayList. And assume that I
don't what properties are inside this instance/class. As I know I can
use Reflection to get the properties.

Now, assume that I got the properties programmaticall y, let them be
Count and Capacity.

How can I access the Count and Capacity for this 'instance',?

regards,
john

Feb 23 '06 #1
2 1534
>How can I access the Count and Capacity for this 'instance',?

PropertyInfo.Ge tValue(yourInst ance)
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 23 '06 #2
Or, more fully:

PropertyInfo countPi = instance.GetTyp e().GetProperty ("Count");
int count = (int)countPi.Ge tValue(instance );

Feb 23 '06 #3

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

Similar topics

2
864
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray that has the information, but we as developers have no way to access this information. I have come up with a solution for the problem, (as I am sure many others have) using reflection. Here is some sample code that will print out the auto...
1
4668
by: Freddy Willockx | last post by:
Hi I'm doing some actions through reflection and generating some source code to speed up my actions. But, when I'm generating source code to read and write the fields of an Enum type, it goes wrong. An internal field "Value__" is added to the field. The problem is that this field is marked as public and not as private. Because this field is marked as public, my code generator assumes, he can
2
1984
by: Mark | last post by:
Am I out of my mind if I use Reflection everytime someone logs into our site to get and track the current Major/Minor/Build/Revision version that the person is viewing our site through? This information would then be logged to a database along with some other information about the user. Thanks in advance. Mark
2
7761
by: Jeff | last post by:
I am trying to dynamically load an assembly via reflection and then invoke a method of that assembly that will populate a custom type collection passed into the method byref. I am able to dynamically load both the DALC component (for the method call) and the Entity component (for the custom type collection to pass in), but I keep getting an error ( Message "Object type cannot be converted to target type.") when invoking the method. If I...
2
3631
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will have a constructor with an int argument
0
2025
by: liko81 | last post by:
I have an Invoice class that must know, directly or indirectly, how to do anything associated with creating, reading, or otherwise processing an invoice to a customer. It is an uber-DAO object that combines the business logic and DAO layers. The invoice it handles can have one to many lines. The most logical implementation is an Invoice object with an array of InvoiceLine objects. We of course want to prevent Joe Programmer from directly...
5
318
by: =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post by:
Hi, is it faster to access the fields from an object directly by using reflection than accessing them by their properties using reflection? Thanks Christian
5
1394
by: DesCF | last post by:
What exactly is Reflection ? I've looked at the definition in Help but I don't find it very helpful! I just stare at it blankly and can't quite seem to grasp its meaning conceptually. Reflection implies something reflected. Does anyone have a good cogent description of its meaning ? Des
17
2300
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection to build a compiler? One that will construct a user defined class "on the fly" (literally, the user defines a class, instantiates it, and runs it from the console mode, all the while prompted by the program)? I guess so, but my final question...
0
8240
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, 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...
0
8175
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8680
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8336
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,...
1
6111
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 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...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2610
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.