开发者

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

开发者 https://www.devze.com 2023-03-11 06:42 出处:网络
[MyCustomClassAttribute] public class Foo { } public class Bar<T> where T : ?? { public T FooInstance;
[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 mak开发者_C百科e it so that T has to have a [MyCustomClassAttribute] on it?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消