consider scenario.
- there
structcolor(written else) - there
enum colorcodeimplements html named color codes. - there's static function converts
colorcodecolor i want able this:
color tmp = ....; tmp = colorcode.aqua;
how do without copy-pasting text 140 times?
i don't care colorcode (enum, class, whatever) long above line works.
problem:
c# not allow me define operators enums. not have macros make nice human-readable table within colorcode.
restriction:
contents of colorcode should available ints, should assignable/ convertible color.
code fragments:
public enum colorcode{ aliceblue = 0xf0f8ff, antiquewhite = 0xfaebd7, aqua = 0x00ffff, aquamarine = 0x7fffd4, azure = 0xf0ffff, ///repeat 140 times ... } public static color colorfromcode(colorcode code){ .... }
you write extension method on enum:
public static color tocolor(this colorcode colorcode) { ... } then have:
color tmp = colorcode.aqua.tocolor(); it's not quite implicit conversion, it's readable you're get.
Comments
Post a Comment