Hi,
In my application I always return deep copies of classes
that are returned from get methods of properties. I do this
so that the class returned can't be changed by getting it and
then manipulating the reference returned.
The problem is when I need to change what's inside the class
returned, I think the code below will be clearer!
Class LineStyle
{
private int lineWidth
property LineWidth
{
get
{
return lineWidth;
}
set
{
lineWidth = value;
}
}
Class Shape
{
private LineStyle mLineStyle
property LineStyle ShapeLineStyle
{
get
{
// Return a deep copy
return new LineStyle(mLineStyle)
}
set
{
mLineStyle = new LineStyle(value);
}
}
}
The problem is that I want to do:
Shape.LineStyle.Width = someValue
and for that to be reflected in the shape object
Perhaps I should just always return references from
get methods???
Help much appreciated
Tristan.