I have a Person and an Organisation Entity: Person looks like this:
public class PersonEntity
{
public string FirstName {get;set;}
public string LastName {get;set;}
public bool IsValid(PersonEnum Attribute, string AttributeValue)
{
if(attribute == PersonEnum.FirstName && AttributeValue == null)
return false;
if(attribute == PersonEnum.LastName && AttributeValue == null)
return false;
return true;
}
}
I have a PersonEnum //Created just to support IsValid Method.
public enum PersonEnum
{
FirstName, LastName
}
Similarly Organisation has an Entity and an Enum.
I want to create a Helper class as following to have all validations at one place, I want to pass the name of Class (Entity), its member (Enum) and value:
public class Helper
{
//Not sure how to pass A Class def and an attribute.
public static ValidateEntityAttribute(*[EntityEnum]*,*[EntityEnum]*, Value)
{
.. do something that looks at the Entity and call it's IsValid method.
}
}
Can It be done without using Reflection, I also want this to be generic so I can use it for all my entities.
Any Suggesstions?