myermian
myermian

Reputation: 32525

C# Generic - Any way to declare T has an attribute?

[MyCustomClassAttribute]
public class Foo
{
}


public class Bar<T>
    where T : ??
{
    public T FooInstance;
}

I'm pretty sure this is impossible, but just thought I'd check. Any way to make it so that T has to have a [MyCustomClassAttribute] on it?

Upvotes: 7

Views: 1260

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

I am afraid this is impossible. Here's a list of all the possible generic constraints you could use.

Upvotes: 5

Related Questions