First let me try to explain my situation.
Since we can not add a string value to an enumeration and I am NOT adding a custom parameter class in order to store and read it (for performance reasons since reflection is involved if I use something like: public class StringValueAttribute : Attribute
), so I decided to use the following type of class:
public class Permissions
{
public const string X1 = "X1";
public const string X2 = "X2";
public const string X3 = "X3";
....
public const string X43 = "CAN_HAVE A LONG NAME AND NOT FOLLOWING A PATTERN";
}
Now I want to create a method that will receive a string as a parameter. However, I want to force the programmer to use only strings
from the class Permissions
.
If I would have used an enumeration, this would not be a problem since the method parameter type is explicity defined.
When we are working with generics we can implement this type of constrains. Is there anything "LIGHT/FAST" that I am not aware that allows me to do this in my case?