By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,453 Members | 1,562 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,453 IT Pros & Developers. It's quick & easy.

Properties returning a class that need to be modified

P: n/a
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.
Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.