问题描述
我想继承来自List< T>并为此新类创建自定义验证属性。但它永远不会进入属性中的验证。
[AttributeUsage(AttributeTargets.Class,AllowMultiple = false)]
$
public class MyAttribute: ValidationAttribute {...}
[MyAttribute]
公共类MyList< T>:List< T> {...}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class MyAttribute: ValidationAttribute{...}
[MyAttribute]
public class MyList<T>:List<T>{...}
有人可以提供帮助吗?
谢谢
推荐答案
编辑:好吧,如果你自己进行验证,你可以读取继承类的属性。您只需要反映theObject.GetType()而不是typeof(theClass)。但如果您无法修改验证码,则无法执行此操作。
Well, if you do the validation yourself, you could read the attributes on the inherited class. You would just reflect on theObject.GetType() instead of typeof(theClass). But you can't do this if you can't modify the validation code.
这篇关于验证属性不适用于List< T>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!