Consider a Web API project with lots of controllers and methods. Said API uses the data transfer object pattern to get the data from the client and to return the results. Those DTO objects are an implementation detail from the point of view of the api, so they are marked as internal
to avoid external code being able to see or call them. How does one avoid having to put suppression attributes on the get
and set
of properties in the dtos for the CA1811 warning?
Right now I'm having to suppress the warnings for each property depending on if the class is a "read" dto, a "write" dto or both. In those cases, the properties need to exist because the json serializer depends on them.
I don't want to open up the classes by marking them public
because then I'm exposing something that only the api project should know about, and static tools will not be able to tell if some classes or fields are not being used, because someone else could be using them from the outside.
I could also migrate the DTOs to a separate project and disable the warnings there, but then I'd either need to mark them public
again or add a InternalsVisibleTo
so that the api project can see them, which negates the benefits again because of this problem.