Long story short: I made a RequireNonDefaultAttribute (I mainly needed it for guids in my DTOs)
[AttributeUsage(AttributeTargets.Property)]
public class RequireNonDefaultAttribute : ValidationAttribute
{
public RequireNonDefaultAttribute()
: base("The {0} field requires a non-default value.")
{
}
public override bool IsValid(object value)
{
return !Equals(value, Activator.CreateInstance(value.GetType()));
}
}
and as the name states it's an attribute that requires the property in the DTO not to be the default of the current type. Everything was working fine. I thought why not use == instead of the Equals method. Since == is more C# style. So I transformed my code into
public override bool IsValid(object value)
{
return !(value == Activator.CreateInstance(value.GetType()));
}
Anyway the expression always got evaluated to false. Can I get some explanation why does this happen?