(disclaimer: I never tested such solution, it's only an idea)
To handle all possible values, you may use the C# compiler directly to generate on the fly the enumeration, with your values. If the compilation fails, the enum's value is not valid.
You can try the code of this other SO question :
CodeTypeDeclaration type = new CodeTypeDeclaration("BugTracker");
type.IsEnum = true;
foreach (var valueName in new string[] { "Bugzilla", "Redmine" })
{
// Creates the enum member
CodeMemberField f = new CodeMemberField("BugTracker", valueName);
type.Members.Add(f);
}
OldAnswser, before understanding your requirement :
I don't think using RegEx is the right way.
What you want to do can be coded like this :
enum MyEnum {
Val1,
Val2,
Val3
}
class MyClass {
void Foo(){
string someInput = "Val2";
MyEnum candidate;
if(Enum.TryParse(someInput, out candidate)){
// DO something with the enum
DoSomething(candidate);
}
else{
throw new VeryBadThingsHappened("someInput is not a valid MyEnum");
}
}
}