【发布时间】:2011-08-03 16:47:43
【问题描述】:
我在 C# 4.0 中使用 customvalidation 属性编写了一个自定义验证方法。我正在使用 Entity Framework 4.1 的代码。但是,自定义验证属性方法是静态的。如何在引用同一类中的其他非静态字段的同时验证我的类中的一些其他逻辑。
即
public class Foo
{
[CustomerValidation(typeOf(Foo), "ValidatePoints"]
public string Points { get; set; }
public string AdvancedPoints { get; set;}
public static ValidationResult ValidatePoints(string _Name)
{
if (_Name != AdvancedPoints) //Note that AdvancedPoints here is non-static and should not be here. but i want to know how i can achieve this.
{
return ValidationResult.Success;
}
else
return new ValidationResult("Wrong entry");
}
}
【问题讨论】:
标签: c# c#-4.0 annotations entity-framework-4.1