Is it possible to specify that a enum property can only have a range of values?
enum Type
{
    None,
    One,
    Two,
    Three
}
class Object
{
    [AllowedTypes(Type.One,Type.Three)]
    Type objType { get; set; }
}
Something like this? Maybe some validator in enterprise library that I don't know of ?!
Ty
You can assign different values to enum member. A change in the default value of an enum member will automatically assign incremental values to the other members sequentially.
Inheritance Is Not Allowed for Enums.
An enum can, just like a class , have attributes and methods. The only difference is that enum constants are public , static and final (unchangeable - cannot be overridden). An enum cannot be used to create objects, and it cannot extend other classes (but it can implement interfaces).
Yes, we can define an enumeration inside a class. You can retrieve the values in an enumeration using the values() method.
You could do the validation in setter logic.
EDIT: some example:
class Object
{
    private Type _value;
    public Type objType{ 
        get{ return _value; }
        set{
            if(value != Type.One && value != Type.Three)
                throw new ArgumentOutOfRangeException();
            else
                _value = value;
        }
    }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With