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

Getting Property Name from an Object?

Is it possible to get property name from an Object? For example I have this
class:

public class Person {
public string Address {get; set; }
}
Is there a way to get the property name "Address"?

Person p = new Person();
p.Address = "test"; // normally, we would know the name

p.PropertyName[0]; // This would return the name "Address", Does C# got
something like this??


Nov 16 '05 #1
2 1401
Sort of, but you will have to adapter the API to suite your needs. Take a
look at Reflection. This allows you to get class information at runtime,
including the list of properties available.

"Alan No Spam" <al*********@xxxxxxxx324354.com> wrote in message
news:ku********************@rogers.com...
Is it possible to get property name from an Object? For example I have this class:

public class Person {
public string Address {get; set; }
}
Is there a way to get the property name "Address"?

Person p = new Person();
p.Address = "test"; // normally, we would know the name

p.PropertyName[0]; // This would return the name "Address", Does C# got
something like this??


Nov 16 '05 #2
hi
System.Reflection and PropertyInfo Class is the way
Take a look at it in the MSDN
regards

Ansil
Dimensions
an****@gmail.com

"Alan No Spam" wrote:
Is it possible to get property name from an Object? For example I have this
class:

public class Person {
public string Address {get; set; }
}
Is there a way to get the property name "Address"?

Person p = new Person();
p.Address = "test"; // normally, we would know the name

p.PropertyName[0]; // This would return the name "Address", Does C# got
something like this??


Nov 16 '05 #3

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

Similar topics

3
by: Pavils Jurjans | last post by:
Hallo, Is there some decent way how to get the object class name in a string format? Currently I use this: function getClassName(obj) { if (typeof obj != "object" || obj === null) return...
31
by: Thanos Tsouanas | last post by:
Hello. I would like to have a quick way to create dicts from object, so that a call to foo would return obj.bar. The following works, but I would prefer to use a built-in way if one exists. ...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
1
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
5
by: jdzemke | last post by:
I am getting 'options' is null or not an object using when using a dynamic dataset with a dropdown list in an html form. I am filling-in a text field and filtering the values in the drop-down. ...
7
by: RSH | last post by:
This is probably a very simple question but... How do I get the instantiated name of an object from within the class? Example: Sub main Dim c1 as new TestClass() c1.PrintName()
2
by: RSH | last post by:
I have a situation where I am creating a class (oValue) that contains two properties "Name" and "Value". I am using a thrid party grid control which has a DropDownList Control. The...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
0
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the...
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
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?
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
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
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
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...
0
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...

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.