Skip to content
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

Open
Rekkonnect opened this issue Jul 22, 2021 · 0 comments
Open

Specific type member constraints for generic type arguments #40

Rekkonnect opened this issue Jul 22, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Rekkonnect
Copy link
Owner

Rekkonnect commented Jul 22, 2021

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:

  • Member kind (required)
  • Member name (required)
  • Member accessibility (optional)
  • Member return type (optional)

For properties or events:

  • Accessors (optional)

For functions:

  • Argument types (optional)
  • Generic information (arity, constraints) (optional)

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.

public class RequiredFieldTypeConstraintAttribute { }
public class RequiredPropertyTypeConstraintAttribute { }
public class RequiredEventTypeConstraintAttribute { }
public class RequiredMethodTypeConstraintAttribute { }
public class RequiredConstructorTypeConstraintAttribute { }

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.

@Rekkonnect Rekkonnect added the enhancement New feature or request label Jul 22, 2021
@Rekkonnect Rekkonnect added this to the 1.x milestone Jul 22, 2021
@Rekkonnect Rekkonnect self-assigned this Jul 22, 2021
@Rekkonnect Rekkonnect modified the milestones: 1.x, 1.3 Jul 29, 2021
@Rekkonnect Rekkonnect pinned this issue Aug 11, 2021
@Rekkonnect Rekkonnect modified the milestones: 1.3, 1.4 Aug 16, 2021
@Rekkonnect Rekkonnect removed this from the 1.4 milestone Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant