9
I am wondering if C# supports optional properties as the following
public class Person
{
public string Name { get; set;}
public optional string NickName { get; set;}
...many more properties...
}
so that when I create a Person object I can easily check the validity of input values in a simple loop
public bool IsInputOK(Person person)
{
foreach( var property in person.GetType().GetProperties())
{
if( property.IsOptional())
{
continue;
}
if(string.IsNullOrEmpty((string)property.GetValue(person,null)))
{
return false;
}
}
return true;
}
I have searched on google but didn't get desired solution. Do I really have to hand code validation code for each property manually?
Thanks.