Contrary to what the title might make you believe; this is not a n00b
question.
I recently came across a problem with using a property which made me
question the way I use/see properties in general. The problem was with
changing item values in a DataRow. The dotNET DataRow class has a
ItemValues property which returns an object array containing item
values.
I tried to change some of these values by passing this object array to
a method using the property as a parameter:
this.DoSomething(row.ItemArray);
But allas, ItemArray does not actually return the internal item value
list but a copy in the shape of an object array. I thought (and still
do) this was strange, I only use properties for controlled access to
my private member variables and avoid putting logic in get/set blocks
and when using a property I expected to access a private member
variable as well. What is even worse is that I had to use Reflector to
find out what ItemArray actually does, since it's not documented in
MSDN (for as far as I can find). This leads to tedious trial-and-error
(although I've managed with my view of Properties so far ;)
If the behaviour of ItemArray is something that might be expected then
using the following code is very dangerous:
this.DoSomething(myObject.HisProperty.HerProperty. TheirProperty);
Especially when a property value is(/might be) changed allong the way.
To be absolutely safe this should be rewritten to something like;
object a = myObject.HisProperty;
object b = a.HerProperty;
object c = b.TheirProperty;
this.DoSomething(c);
b.TheirProperty = c
a.HerProperty = b
myObject.HisProperty = a
Here:
http://msdn.microsoft.com/library/de...guidelines.asp
MS states that a method should be used if an array is returned.
See here for code examples:
http://www.navelpluis.nl/index.php?o...id=21&Itemid=5
So what defines a propertie and what can be expected from it?