I am working on a requirement where in I need to check my ASP.NET Model Property for a value 000000.If the value is 000000 then it should be displayed as blank string. I thought of achieving this using implicit operators. Here is my model class
public class OrgName
{
private string Value { get; set; }
public static implicit operator string(OrgName org)
{
return org.Value;
}
public static implicit operator OrgName(string value)
{
bool isAllZeros = value.Where(x => char.IsDigit(x)).All(x => x == '0');
if (isAllZeros)
value = string.Empty;
return new OrgName() { Value = value };
}
}
The problem is that we are using reflection to set property values.The above code does not work and the property is always displayed as blank.
Can someone help me out with this? I am also open to other suggestions to achieve this.
Thanks
Aucun commentaire:
Enregistrer un commentaire