In my solution i depend heavily on Dictionaries with an enum as a key. I find it is easy to understand and to read this construction.
One significant obstacle to the above is that it is not possible to serialize this. See Problems with Json Serialize Dictionary<Enum, Int32> for more info on this.
My question is:
Is there a equally readable and intuitive pattern for replacing the Dictionary<enunm,object>
that is json serializable with the built in json serializer?
Today I have replaced a.Instance.QueryableFields[Fields.Title]
with a.Instance.QueryableFields[ Fields.Title.ToString()]
. Not very elegant, and it is opening up for errors.
When serializing it, just select the string value. It's not very neat, but it works.
a.Instance.QueryableFields.ToDictionary(x => x.Key.ToString(), x => x.Value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With