I was wondering if it was impossible to set up an accessor to allow you to access the accessor’s variable..
Example of an error:
public void Main()
{
Object.name = "test"; //Can't access the object's subproperties
}
Objec ob = new Objec();
public Objec Object
{
get { return ob; }
set { ob = value; }
}
class Objec
{
string name;
string value;
}
Is there anyway to do the above (other than making accessors for every value)?
Thanks,
Max
EDIT: Here is a better example
public void Main()
{
//Now I can't change the X or Y properties, this will display an error
ThePoint.X = 10;
//To change the x value, I need to do the following:
ThePoint = new Point(10,0);
}
private Point Poi = new Point();
public Point ThePoint
{
get { return Poi; }
set { Poi = value; }
}
Is there a way to make ‘ThePoint.X’ work (without just publicly displaying ‘Poi’)?
The answer to your actual question “Is there anyway to do the above (other than making accessors for every value)?” is NO.
Guessing a bit on your intentions, you seem to want to follow a design pattern known as Bridge (your class is an abstraction around the implementation of
Objectand/orPoint). You will only expose to your class’ audience the pieces of the original implementation that you want, in your question’s case, every value.