I am about to implement a class to represent a validation error. The class would definitely contain a string value called Message, which is a default message to display to a user. I also need a way to represent what the validation error is to the programmer. The idea is that there should be an easy way to determine if a particular validation error occurred.
It would be simple to implement a string member called Type, but to determine if a ValidationError is of that type, I would need to remember the string that describes that type.
if (validationError.Type == "PersonWithoutSurname") DoSomething();
Clearly, I need something more strongly typed. An enumeration would be good:
if (validationError.Type == ValidationErrorType.PersonWithoutSurname) DoSomething();
But given the potentially hundreds of types of validation error, I could end up with an ugly enum with hundreds of values.
It also occurred to me to use subclassing:
if (validationError.GetType() == typeof(PersonWithoutSurnameValidationError)) DoSomething();
But then my class library is littered with hundreds of classes which will mostly be used once each.
What do you guys do? I can spend hours agonising over this sort of thing.
Answer go to whoever comes up with the suggestion I use. Enum suggestion is the one to beat.