Can I freely add additional operations in C# public property’s getter and setter? To what extent?
For example, would the following piece of code be okay (returning and editing a collection which is nested into another collection)?
public ObservableCollection<MyEntity> MyCollection
{
get
{
return myColl.Where(p => p.Name == myName).FirstOrDefault().AnotherCollection;
}
private set
{
myColl.Where(p => p.Name == myName).FirstOrDefault().AnotherCollection = value;
}
}
The only bound is the semantics. You may use whatever operations you find suitable, as long as the general property semantics is preserved. Among others, I would check that
If you keep the semantics, IMHO any operation is allowed.