?
Solved

Indexed properties on custom class

Posted on 2008-11-03
2
Medium Priority
?
416 Views
Last Modified: 2013-12-17
I have a custom class (ControlPropertiesBase) whith the following fields (see code).
Several other classes (derived from WebControls) have the property ControlProperties, which is derived from the ControlPropertiesBase, plus other properties / fields.

Is it possible to access the properties via indexing like myControl.Properties["TabOrder"], and if so how can I do that?
[Serializable]
public class ControlPropertiesBase
{
	public string Name;
	public string Label;
	public string LabelTranslated;
	public int TabOrder;
	public bool Compulsary;
	public bool ReadOnly;
	public bool Visible;
}
 
public class DropDownListControl : DropDownList
{
	[Serializable]
	public class ControlProperties : ControlPropertiesBase
	{
		public ControlProperties() { }
		public Hashtable Items;
	}
 
	private ControlProperties _properties = new ControlProperties();
	public ControlProperties Properties
	{
		get { return _properties; }
		set { _properties = value; }
	}
 
	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);
		this._properties = new ControlProperties();
	}
}

Open in new window

0
Comment
Question by:Albert Van Halen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 1

Expert Comment

by:Nullable
ID: 22871528
u can use this code :)



this._properties = new ControlProperties();
 
_properties.Label = "Nullable";
 
string labelvalue = _properties.GetType().GetField("Label").GetValue(_properties).ToString();

Open in new window

0
 
LVL 1

Accepted Solution

by:
Nullable earned 2000 total points
ID: 22871633
u Can use this code

i test it and it will be work



public class ControlProperties : ControlPropertiesBase
        {
            public ControlProperties() { }
            public Hashtable Items;
            public object this[string index]
            {
                get
                {
                    return this.GetType().GetField(index).GetValue(this).ToString();
                }
                set
                {
                    this.GetType().GetField(index).SetValue(this, value);
                }
            }
        }
 
// Use code :
 
string labelvalue = _properties["Label"] as string;

Open in new window

0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question