types - C# code merging with enums with slight differences -
i have merge c# codes 2 similar solutions have issue enums. projects use .net2.0 , have use well. projects have common class contains enum same name difference:
using system; using system.collections.generic; using system.text; using system.net; namespace myproject { public enum letters { non = 0, = 1, b = 2, c = 3 } public class myclass { public int v = 0; . . . public letters lt = 0; // enum } }
there many other uses of "enum" like:
tmpchild.type == typeof(letters); this._data.ltr = (letters)valuelistupdown_lts.value; adddata(new sfunc(0,typeof(letters), letters.a)); letters letters = letters.a;
the second project identical enum looks this:
public enum letters { = 0, b = 1, c = 2 }
there many various uses of these enums in code , code has many projects use assembly refference. know best way merge solutions. think method returns enum type according string don't know how implement or use returned type in cases.
please advice
---------- edit ----------
some other constraints have are:
i can't use nullable type or change enums values (i can change names) because in cases there serializers write , read to\from file.
i think of using method this:
public static type letters(string letters_type) { if (letters_type == "type_a") return typeof(letters); return typeof(letters_b); }
but don't know how cast , use type enum in each case @ runtime know version of enum should use, that's why such method can help.
thanks
if main intention merge 2 codebases , remove duplication, firstly use resharper rename 1 of enums in 1 of projects, merge codebases replace of references second enum (the 1 without "non") reference first enum, , ensure "+1" them.
i think might consider nullable enum, rather "magic" 0 value. not sure if available in .net 2.0 though. also, beware of using auto-mappers when using nullable enums, can set values 0 if you're not careful.
Comments
Post a Comment