Extend Enum

Ali Çehreli acehreli at yahoo.com
Mon Jan 23 14:48:02 PST 2012


On 01/23/2012 02:38 PM, Mars wrote:
> Hello everybody.
> I'd like to know if there's a way, to extend an Enum, based on version().
> I have an Enum, that holds various values, but some are different, in
> other versions. So the alternative would be to define the Enum several
> times.
>
>> version(x)
>> {
>> enum example
>> {
>> FOO = 1,
>> BAR = 2,
>> }
>> }
>> else
>> {
>> enum example
>> {
>> FOO = 1,
>> BAR = 3,
>> }
>> }
>
> Is there a better way to do this? Maybe a class with static consts...?
> How should I do it?
>
> Mars

If it makes sense, you can use version(x) blocks within the single enum 
definition, as opposed to putting version(x) outside. Alternatively, it 
may make sense to define the enum value(s) outside to keep the 
definition of 'example' relatively clean:

     version(x) {
         enum BAR_VALUE = 2;

     } else {
         enum BAR_VALUE = 3;
     }

     enum example
     {
         FOO = 1,
         BAR = BAR_VALUE,
     }

Ali


More information about the Digitalmars-d-learn mailing list