i've got enum class full of command line switches third party app..i'm trying make can call on item in enum .toswitch (or whatever) can make validate value type, spit out formatted command-line switch parameter value. maybe i'm going wrong. after sitting here day working on (it's big) i'm finding hard let go , explore different approach. lol suggestions?
desired result:
console.writeline(enumclass.enumitem.toswitch("option"));
would spit out: -x "option"
for specific enum:
public enum myenum { value1 = 1, value2 = 2, } public static class enumextensions { public static string toswitch(this myenum val, string option) { switch (val) { case myenum.value1 : return "x " + option; case myenum.value2 : return "y " + option; default: return "error"; } } }
another way you're talking dictionary
, might preferable. keys switch (or enum value), , value command format. like:
dictionary<string, string> cmdformats = new dictionary<string, string>() { { "-a", "filename" }, { "-n", "number" } };
i suspect more maintainable defining enum.
Comments
Post a Comment