+ static bool TypeImplementsIDictionary (Type type)
+ {
+ foreach (var iface in type.GetInterfaces ())
+ if (iface == typeof (IDictionary) || (iface.IsGenericType && iface.GetGenericTypeDefinition () == typeof (IDictionary<,>)))
+ return true;
+
+ return false;
+ }
+
+ // it also supports contract-based dictionary.
+ private DictionaryTypeMap RegisterDictionary (Type type)
+ {
+ if (!TypeImplementsIDictionary (type))
+ return null;
+
+ var cdca = GetAttribute<CollectionDataContractAttribute> (type);
+
+ DictionaryTypeMap ret =
+ new DictionaryTypeMap (type, cdca, this);
+
+ if (FindUserMap (ret.XmlName) != null)
+ throw new InvalidOperationException (String.Format ("Failed to add type {0} to known type collection. There already is a registered type for XML name {1}", type, ret.XmlName));
+ contracts.Add (ret);
+
+ TryRegister (ret.KeyType);
+ TryRegister (ret.ValueType);
+
+ return ret;
+ }
+