Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RestrictedEnum<T> where T : struct {
- private System.Enum value;
- public T Value { get { return (T)(object)value; } }
- public RestrictedEnum() {
- if ( !typeof(T).IsEnum ) throw new NotSupportedException();
- value = null;
- }
- public bool SetFlag( Enum flag ) {
- bool checkEnum = Enum.IsDefined( typeof( T ), flag );
- if ( checkEnum ) value = flag;
- return checkEnum;
- }
- public bool HasFlag( Enum flag ) {
- return ( Enum.IsDefined( typeof( T ), flag ) ) ? Enum.Equals( value, flag ) : false;
- }
- public T Parse() {
- return (T)(object)value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement