Let's say I have a POCO like so:
public class Name
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
FirstName and LastName cannot be null. Should I add in a method like this:
public List<Error> Validate()
{
var errors = new List<Error>();
if (String.IsNullOrEmpty(FirstName))
errors.Add(new Error("FirstName", "You must fill out first name."));
if (String.IsNullOrEmpty(LastName))
errors.Add(new Error("LastName", "You must fill out last name."));
}
where Error
is a struct that contains a NameValueDictionary
. Is this a good way of doing things? I can potentially see a problem with the repository where someone attempts to save this POCO without running it through Validate()
first.