Link to home
Start Free TrialLog in
Avatar of Albert Van Halen
Albert Van HalenFlag for Netherlands

asked on

Indexed properties on custom class

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

Avatar of Nullable
Nullable
Flag of Iran, Islamic Republic of image

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

ASKER CERTIFIED SOLUTION
Avatar of Nullable
Nullable
Flag of Iran, Islamic Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial