私は解決策を見つけました。ここでは、カスタムNotEqual属性を作成します。
public class RenameCompare
{
public string OldName { get; set; }
[NotEqual(PropName="OldName", ErrorMessage="The oldname and new name are equal!")]
public string NewName { get; set; }
}
public class NotEqualAttribute : ValidationAttribute
{
public string PropName { get; set; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
PropertyInfo otherPropertyInfo = validationContext.ObjectType.GetProperty(PropName);
var otherPropertyStringValue = otherPropertyInfo.GetValue(validationContext.ObjectInstance, null).ToString();
if (Equals(value.ToString(),otherPropertyStringValue))
{
return new ValidationResult(FormatErrorMessage(validationContext.DisplayName));
}
return null;
}
}