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

How to get property name?

if I have a public static property such as:

//Class1
public class Class1
{
public static Dictionary<string, string> Prop1{...}
public static Dictionary<string, string> Prop2{...}
}

//SomeClass
public class SomeClass
{
public SomeClass ( CustomDictionary<string, string> pdict )
{//get name of pdict here}
}

// usage
SomeClass myProp1 = new SomeClass( Class1.Prop1 );

How can I get the name of pdict in SomeClass()? Meaning, I want a
string containing "Prop1".

Thanks,
Brett

Jun 15 '06 #1
3 11524
Brett Romero wrote:
if I have a public static property such as:

//Class1
public class Class1
{
public static Dictionary<string, string> Prop1{...}
public static Dictionary<string, string> Prop2{...}
}

//SomeClass
public class SomeClass
{
public SomeClass ( CustomDictionary<string, string> pdict )
{//get name of pdict here}
}

// usage
SomeClass myProp1 = new SomeClass( Class1.Prop1 );

How can I get the name of pdict in SomeClass()? Meaning, I want a
string containing "Prop1".


You can't unless you provide a mechanism for them to specifically tell you.
You are getting a reference to an object of type
CustomDictionary<string,string>. You have no way of know that the object
was originally created in the static get_Prop1. What if get_Prop1 had
delegated the creation of its type to some different method? What would you
want to get?

BTW, your code seems upside down. I would expect a CustomDictionary to
derive from Dictionary. If that is the case, a constructor expecting a
CustomDictionary will not be able to accept an object of type Dictionary.
--
Tom Porterfield

Jun 15 '06 #2
Use TypeDescriptor.GetProperties() - take a look at Help. A property
descriptor collection will be returned. You can look up various values of a
property, including its Name.

Hope this helps.

-=Gary

"Brett Romero" wrote:
if I have a public static property such as:

//Class1
public class Class1
{
public static Dictionary<string, string> Prop1{...}
public static Dictionary<string, string> Prop2{...}
}

//SomeClass
public class SomeClass
{
public SomeClass ( CustomDictionary<string, string> pdict )
{//get name of pdict here}
}

// usage
SomeClass myProp1 = new SomeClass( Class1.Prop1 );

How can I get the name of pdict in SomeClass()? Meaning, I want a
string containing "Prop1".

Thanks,
Brett

Jun 15 '06 #3
Sorry Tom. I meant to put Dictionary.

Gary wrote:
Use TypeDescriptor.GetProperties() - take a look at Help. A property
descriptor collection will be returned. You can look up various values of a
property, including its Name.


I've tried the msdn example for this and still don't get the name I'm
looking for. I will just define the property names in static strings.

Brett

Jun 15 '06 #4

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

Similar topics

11
by: Laszlo Zsolt Nagy | last post by:
My problem is about properties and the virtuality of the methods. I would like to create a property whose get and set methods are virtual. I had the same problems in Delphi before and the solution...
4
by: Jimbo | last post by:
I am sort of new to C#. Currently have a private property called "_name" in a class. I have written a public getter and setter routine for it called "Name". Currently, the getter for the...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
0
by: doubts | last post by:
Hi, I have a query regarding reading Image Property for button from a XML file . I read XML files to Generate Screens using System.Windows.Forms.Controls .The XML file is read and properties...
1
by: doubts | last post by:
Hi, I have a query regarding reading Image Property for button from a XML file . I read XML files to Generate Screens using System.Windows.Forms.Controls .The XML file is read and properties...
5
by: ronlahav | last post by:
Dear all i Wonder how can i edit a node property (in C# not by hand :) ) i have the follwing XMl file (hibernate.cfg.xml) <?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration ...
11
by: Andrus | last post by:
I'm implementing entity object which should populate its properties from database when property is first referenced. In RDL reports I use object properties like MyObject.MyProperty MyObject...
3
by: Peter Gast | last post by:
Hi, I need as a parameter for a control the names of my properties as a string. How can I get the name of the property as a string during runtime Example: Private _MyVar As Double Public...
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:
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
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
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...

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.