This repository was archived by the owner on Feb 19, 2024. It is now read-only.
Specific type member constraints for generic type arguments #40
Labels
enhancement
New feature or request
Credits
Suggested by @ZacharyPatten
Summary
This feature is about having specific constraints about requiring certain members, including fields, properties, functions, events, and so on.
Functionality Design
The available constraint information would be:
For properties or events:
For functions:
Such constraints can also be generalized on type constraint profiles.
API Design
Attributed Declaration
This feature introduces 6 new attributes that can be assigned to both interfaces (type constraint profiles) and directly on the type parameters themselves.
Each of those attributes declares that a required member of the specified member kind be declared with the aforementioned properties.
The only unsupported feature of attributed declaration is generic type constraint clauses. This is intentionally unsupported due to the complexity it adds to both the analyzer, and the end user that may wish to apply such constraints. Instead, templated declaration is preferred.
Templated Declaration
The aforementioned attributes may also be used in declaring the required member from an already explicitly declared member, acting as a template. In other words, a member found in a (preferably sealed) instance class type can act as a template for a required member declaration. Its accessibility, name, return type, etc. will all be taken into account. Instance class types are preferred for this case so that accessibility does not require an extra declaration attribute. An additional analyzer-internal identifier can be also declared on the member through the
RequiredMemberTypeConstraintTemplateAttribute
attribute.The text was updated successfully, but these errors were encountered: