Skip to content

[Proposal] Allow generic attributes #953

@ashmind

Description

@ashmind

Problem

For some attributes (e.g. TypeConverterAttribute) that are used to reference types, the current usage looks like this:

[TypeConverter(typeof(X))]

This has two disadvantages:

  1. You can't guarantee that the type matches the requirements of the attribute -- e.g. has an empty constructor or inherits TypeConverter.
  2. The syntax is a bit verbose.

Suggestion

I suggest that the generic attributes should be supported, including any generic constraints.
Usage example:

[TypeConverter<X>]
Pros
  1. Support for type constraints in type-referencing attributes
  2. Shorter syntax
  3. As far as I know, generic attributes are already supported in IL
Cons

The set of attributes that benefit from this might not be that large.

Updates

Removed pro 4 as it wasn't a pro.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions