In my domain object, I map 1: M relationships to the IList property.
For good isolation, I do it read-only as follows:
private IList<PName> _property;
public ReadOnlyCollection<PName> Property
{
get
{
if (_property!= null)
{
return new ReadOnlyCollection<PName>(new List<PName>(this._property));
}
}
}
I do not really like ReadOnlyCollection, but did not find an interface for creating a read-only collection.
Now I want to edit the property declaration so that it returns an empty list, and not null
when it is empty, so I edited it as follows:
if (_property!= null)
{
return new ReadOnlyCollection<PName>(new List<PName>(this._property));
}
else
{
return new ReadOnlyCollection<PName>(new List<PName>());
}
but Property
always null when I get it in my test.
source
share