After a extensive debugging session I found that the problem was that I called the setter of a readonly property. Is there a trick to provoke a compiler warning when this happens? Because marking the setter private does not work.
Cheers,
CA
To make clear what I mean:
private readonly List<SomeObject> _budget;
public IEnumerable<SomeObject> Budget
{
get
{
return _budget;
}
}
Can be accessed with
A.Budget=new SomeObject();
without compiler {error,warning,message}
You mixed something up here. In your example the compiler will yield an error if you try to do
A.Budget=new SomeObject();if the propertyBudgetin classAdoes not have a setter.From here on I can only assume what your problem is.
My guess is that you would like the collection wrapped in the
Budgetproperty to be readonly. That’s probably why you made itIEnumerable<SomeObject>whereas the private member is aList<SomeObject>. So even if you do do not have a setter you can still do(A.Budget as List<SomeObject>).Add(bla). To prohibit this you can use List.AsReadOnly like this: