Ejemplo n.º 1
0
        // 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);

            TryRegister(ret.KeyType);
            TryRegister(ret.ValueType);

            var map = FindUserMap(ret.XmlName);

            if (map != null)
            {
                var dmap = map as DictionaryTypeMap;
                if (dmap == null)                 // The runtime type may still differ (between array and other IList; see bug #670560)
                {
                    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);

            return(ret);
        }
Ejemplo n.º 2
0
        // 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);
        }