How to set ExpandoObject's dictionary as case insensitive?
I've been using this “Flexpando” class (for flexible expando) which is case-insensitive.
It's similar to Darin's MassiveExpando answer in that it gives you dictionary support, but by exposing this as a field it saves having to implement 15 or so members for IDictionary.
public class Flexpando : DynamicObject {
public Dictionary<string, object> Dictionary
= new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
public override bool TrySetMember(SetMemberBinder binder, object value) {
Dictionary[binder.Name] = value;
return true;
}
public override bool TryGetMember(GetMemberBinder binder, out object result) {
return Dictionary.TryGetValue(binder.Name, out result);
}
}
You may checkout Massive's implementation of a MassiveExpando
which is case insensitive dynamic object.