An alternative to a dictionary with enumeration keys?

In my solution, I am heavily dependent on dictionaries with enumeration as a key. I find it easy to understand and read this design.

One of the significant obstacles to the above is that it is impossible to serialize. See Issues with the Json Serialize Dictionary <Enum, Int32> for more information on this.

My question is:
Is there an equally readable and intuitive replacement template Dictionary<enunm,object>that is serializable json with a built-in json serializer?

Today I replaced a.Instance.QueryableFields[Fields.Title]with a.Instance.QueryableFields[ Fields.Title.ToString()]. Not very elegant, and it opens to error.

+5
source share
2 answers

. , .

a.Instance.QueryableFields.ToDictionary(x => x.Key.ToString(), x => x.Value)
+1

, # Enums :

public enum MyEnum { Zero=0, One, Two };

object[] dictionary = new object[3];
dictionary[(int)MyEnum.Zero] = 4;

EDIT: (. )

Dictionary<Enum, Object> Dictionary<Int, Object>.

-1

All Articles