reflective enums

janderson askme at me.com
Fri Feb 16 20:47:05 PST 2007


renoX wrote:
> Kevin Bealer a écrit :
>> == Quote from renoX (renosky at free.fr)'s article
>>> - why the name getString instead of the usual toString name?
>>
>> That could be changed too; I think of toString() as an object method, and
>> when adding a static method, I figured I should use a different name to
>> avoid conflicting with the method.  I didn't really check whether there
>> is a real conflict on this.
> 
>  From my testing, it doesn't trigger a conflict, but I've only tested it 
> inside one file.
> 
>> There is kind of a strangeness with the way I defined this in that you
>> creating instances of the Enum!(...) struct is not useful.  The type is
>> only really interesting for its static properties.
> 
> About this I was wondering if it wouldn't be less strange to do a 
> template like this:
> 
> // expected usage: DefEnum!("enum ListEnumFoo {A,B=1};")

Advantage: you would be able to reuse the code as a sub-set of something 
else like serialization or another language that uses the same enum syntax.

Disadvantage: Code is harder to understand.  Code runs slower.

-Joel

-Joel



More information about the Digitalmars-d mailing list