I have a nested class for constant values:
public static class Constants
{
public static readonly string None = string.Empty;
public static class FieldOperators
{
public static readonly string A01 = "Foo";
public static readonly string A02 = "Bar";
}
}
I realize that this is not ideal, that Enum
s makes more sense, but I can't change this legacy code. I have to work with what I have.
I am trying to write a helper function that gets me the values based on the full name of the field:
public static string GetFieldValue(string fullname)
{
return ???;
}
For example:
- "Constants.None" would return "" (empty string).
- "Constants.FieldOperators.A01" would return "Foo".
- "Constants.NonExistant.Blah" would return
null
since that does not exist.
Aucun commentaire:
Enregistrer un commentaire