-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make collection properties not-nullable #30
Comments
Collection Properties should be read-only as per MS code guidelines. This allows individual items to be added or removed but the collection itself can't be changed. Your code should look about like this:
|
The DTO converters require a public setter to |
PS: since this is gonna be a maintenance release, removing setters is out of the question. In the same spirit, do not throw on null but fall back to the empty collection. private static readonly CombatAttribute[] Empty = new CombatAttribute[0];
private ICollection<CombatAttribute> attributes = Empty;
public ICollection<CombatAttribute> Attributes
{
get { return this.attributes; }
set
{
this.attributes = value ?? Empty;
}
} |
We can change that, for 1.4, but see #32 for a 2.0 change. |
Entities that have a collection property should initialize that property to an instance of an empty array. Property setters should throw when the given value is null. This is to avoid null reference exceptions when iterating over a collection property.
Example in class
InfixUpgrade
The
Empty
array must be cached to avoid multiple object allocations.The text was updated successfully, but these errors were encountered: