Currently I'm using reflection to check the values if its null or empty. What I want to do is, I want to check all the values of properties from the child class only.
Here is my Parent Class:
public class BaseModel
{
public int is_hidden { get; set; }
public string created_by { get; set; }
public DateTime? created_date { get; set; }
public string last_modified_by { get; set; }
public DateTime? last_modified_date { get; set; }
}
And this is my Child Class
public class company : BaseModel
{
public int id { get; set; }
public string company_name { get; set; }
}
And this is what I did now
public class Validation<T> where T : class, new()
{
ResultStatus rs = new ResultStatus();
public ResultStatus Validate(T ModelName)
{
if (typeof(T).GetProperties().All(propertyInfo => propertyInfo.GetValue(ModelName) != null))
return rs;
else
rs.SetSuccessStatus();
return rs;
}
}
Actually it works well, but my Validation Method is getting whole properties from both of parent and child classes.
I need suggestion how can I get the child class only, or something like exclude the parent class.
Aucun commentaire:
Enregistrer un commentaire