473,388 Members | 1,340 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,388 software developers and data experts.

Value of a property through reflection

Hi, i need help please.. any help would be greatly appreciated. I need to
know how i can get the value of a property throught reflection? please
please.. thanks in advance...
Sep 5 '06 #1
3 26295
object value = obj.GetType().GetProperty("PropertyName").GetValue (obj,
null);

(where obj is your original object, and "PropertyName" is the name of the
public instance property).

Marc
Sep 5 '06 #2
The null passed at the end are binding flags which could enable you to read
private/internal properties too.

Ciaran O'Donnell

"Marc Gravell" wrote:
object value = obj.GetType().GetProperty("PropertyName").GetValue (obj,
null);

(where obj is your original object, and "PropertyName" is the name of the
public instance property).

Marc
Sep 8 '06 #3
Ciaran O''Donnell <Ci************@discussions.microsoft.comwrote:
"Marc Gravell" wrote:
object value = obj.GetType().GetProperty("PropertyName").GetValue (obj,
null);
The null passed at the end are binding flags which could enable you to read
private/internal properties too.
Not quite. The null in the call to GetValue above is the "index" value
in case you're dealing with what in C# terms is an indexer instead of a
property (they're both properties in .NET terminology). The overload
which takes a BindingFlags is a different one (and far less commonly
used, IME) - you'd normally specify the BindingFlags in the call to
GetProperty to get at a private/internal property.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 8 '06 #4

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

Similar topics

3
by: Jürgen Heyn | last post by:
Good morning, on form 2 input elements and 1 image are placed. The 1st (Index) one is "hidden", the 2nd ) is an empty textbox. When clicking the picture I would like to toogle a boolean value....
21
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
1
by: Goos van Beek | last post by:
Hello. I'm using the following code to fill a combobox on a Windows form: private void FillCboRelation(){ using(SqlCommand sqlStatement = new SqlCommand("sp_RelationList",cnn)) {...
1
by: Mudassar | last post by:
i want to get the property value using reflection. Scenerio: i have a status bar on MDI form. it has property named "Panels" and i want to get a specific panel from that panels collection using...
4
by: JuG | last post by:
Hi, Is there any way to display a value in the NumericUpDown control that is bigger than Max or smaller than Min? Especially when I am just creating the control, not when the user changes it...
1
by: Jeffrey Christiansen | last post by:
I wanted to add a toggle button to a VB2005 form to be used for a simple Windows Application (i.e. compiled to a "*.exe"), so I added the ActiveX Microsoft Forms Object toggle button, however I...
4
by: Aamir Mahmood | last post by:
Hi I am unable to access the HasValue and Value properties in an Nullable object. int? i = 9; object value = i; if ((value as Nullable).HasValue) { ... }
2
by: Tony Johansson | last post by:
Hello! What purpose has this Value propery on nullable types because it possible to display their value without using it. For example: int? intNullable1 = 3; int? intNullable2 = 5;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.