The Object Classes...
class Room
{
public string Value1 { get; set; }
public string Value2 { get; set; }
public string Value3 { get; set; }
public Room()
{
this.Value1 = "one";
this.Value2 = "two";
this.Value3 = "three";
}
}
class Building
{
public Room Room-Bob { get; set; }
public Room Room-Steve{ get; set; }
public Building()
{
this.Room-Bob = new Room();
this.Room-Steve = new Room();
}
}
class Street
{
public Building Building-Black{ get; set; }
public Building Building-Blue { get; set; }
public Building Building-Yellow { get; set; }
public Building Building-White { get; set; }
public Street ()
{
this.Building-Black = new Building();
this.Building-Blue = new Building();
this.Building-Yellow = new Building();
this.Building-White = new Building();
}
}
What I am currently using to get the values...
class go
{
public void go()
{
string SelectedValue = "";
Street s = new Street();
string PathToProperty = "s.Building1.Room1.value1";
if(PathToProperty == "s.Building1.Room1.value1") { SelectedValue = s.Building1.Room1.Value1; }
if (PathToProperty == "s.Building1.Room1.value2") { SelectedValue = s.Building1.Room1.Value2; }
}
}
How I would like to get the values... or something similar
string PathToProperty = "s.Building1.Room1.value1";
SelectedValue = PathToProperty;
I would also like to set the property like this...
string PathToProperty = "s.Building1.Room1.value1";
SelectedValue = PathToProperty;
The reason being I am making the the PathToProperty by stringing together the text from a bunch of combo boxes. Ultimately I want to avoid having to add to my list of IF statements as the options inside the combo boxes increase.
I have being messing around with reflection but would like to avoid this , I read somewhere you can do this with interfaces (using them to expose properties) but I do not know how.
If Reflection is the best choice for this can someone show me 2 methods of to get the property and another to set it?