我正在尝试创建一个自定义 When Extensions 来检查我的实体是否有更改。但是我在获取 Propertyname 时遇到了麻烦,这是我在验证实例时需要的。
public static bool WhenHasChanged<T, TProperty>(this IRuleBuilderOptions<T, TProperty> rule)
{
//I need to get the PropertyValidatorContext from the rule
PropertyValidatorContext context;
var instance = (IChangeTrackingObject)context.Instance;
if (false == instance.GetChangedProperties().ContainsKey(context.PropertyName))
{
return true;
}
var oldValue = instance.GetChangedProperties().Get(context.PropertyName).OldValue;
var newValue = context.PropertyValue;
return (null == oldValue) ? null == newValue : oldValue.Equals(newValue);
}
我需要得到正在验证的 PropertyName 和正在验证的实例,通常这些位于PropertyValidatorContext有没有办法PropertyValidatorContext从规则中获取?
牧羊人nacy
相关分类