Faithlife / FaithlifeAnalyzers

C# code analyzers
MIT License
2 stars 11 forks source link

DTO usage #11

Open amanda-mitchell opened 5 years ago

amanda-mitchell commented 5 years ago

If a type is used with JSON-serialization methods (for example JsonUtility.ToJson), raise a warning if the type does not have a Dto suffix.

For types that do have a Dto suffix, verify that all properties are auto-implemented and are of "approved" types:

These will definitely need to be warnings, given the number of historical violations that we have.

ddunkin commented 5 years ago

IReadOnlyCollection or IReadOnlyList?

All properties should be nullable.

ejball commented 5 years ago

IReadOnlyList

dustinsoftware commented 5 years ago

We have a converter for DateTimeOffset, is that being deprecated?

amanda-mitchell commented 5 years ago

I recommend deprecating the DateTimeOffset converter.

Using converters makes it more difficult to create intelligible error messages when deserialization fails—particularly in the case of parameters to ASP.NET actions, where a failure to deserialize results in a 500 instead of a 400.

While this is still something of an issue with type mismatches (for example, a number where a string is expected), I don't see a compelling reason to exacerbate the problem, especially when the first thing we usually do with a DTO is to convert it to/from a domain object, which can have a wider variety of types on it.

amanda-mitchell commented 5 years ago

Additional recommendation: Dto types should be sealed.