C#Generic - 任何声明T的方法都有属性?

m-y*_*m-y 6 c# generics custom-attributes

[MyCustomClassAttribute]
public class Foo
{
}


public class Bar<T>
    where T : ??
{
    public T FooInstance;
}
Run Code Online (Sandbox Code Playgroud)

我很确定这是不可能的,但我想我会检查一下.任何方式使T必须有一个[MyCustomClassAttribute]吗?

Dar*_*rov 5

我担心这是不可能的.这是您可以使用的所有可能的通用约束的列表.