关于Attribute和泛型的问题
泛型 Attribute Filter ASP.NET?MVC MVC
[解决办法]
1。可以把type作为参数传进去,比如:
public class ValidateCodeAttribute : Attribute
{
public ValidateCodeAttribute(Type t)
{
}
}
2。这种情况下可以不用泛型,把type作为参数,跟上面一样。如果一定要用泛型,可以反射调用:
MethodInfo method = typeof(xx).GetMethod("MyMethod");
MethodInfo generic = method.MakeGenericMethod(type);
generic.Invoke(new xx(), null);
[解决办法]
先把要做什么讲明白 不然谁都知道你要干嘛
泛型Attribute啊- - 主帖里面说了的