marinasundstrom / CheckedExceptions

Enforce better exception handling in C#/.NET by ensuring exceptions are explicitly handled.
MIT License
4 stars 0 forks source link

Enhanced handling of Properties with XML doc #23

Closed marinasundstrom closed 1 week ago

marinasundstrom commented 1 week ago

The ThrowsAttribute is versatile. You can put it on various members and constructs - even property accessors. (getter and setter) While we also support XML doc for compatibility either existing libraries, so developers can consume them and get the same benefits, this does come with its drawbacks.

XML docs can't be placed on property accessors, at least it doesn't get recognized. Instead, the property itself carries the information, such as declared exceptions - potentially for both accessors. Thus it might be hard to determine where the exceptions should go.

Currently, we don't deal with this in the right way for properties. We are looking at the accessors for XML doc and exceptions. That needs to change.

We should look at the property itself to gather the exceptions, and then try to figure out where they go, to what accessor to bind it to - in order to display the right diagnostic about thrown exception for the right accessor.

If there is just one accessor, we just attach the exceptions to that.

If there are both accessors, we should look for words in the description of the exception as a clue what accessor they apply to. Words like "gets" and "sets".