Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 796
myermian Avatar asked Jun 06 '11 18:06

myermian


1 Answers

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

like image 53
Darin Dimitrov Avatar answered Sep 28 '22 07:09

Darin Dimitrov