コード例 #1
0
        private SharedContractMap RegisterContract(Type type)
        {
            QName qname = GetContractQName(type);

            if (qname == null)
            {
                return(null);
            }
            CheckStandardQName(qname);
            if (FindUserMap(qname) != null)
            {
                throw new InvalidOperationException(String.Format("There is already a registered type for XML name {0}", qname));
            }

            SharedContractMap ret = new SharedContractMap(type, qname, this);

            contracts.Add(ret);
            ret.Initialize();

            object [] attrs = type.GetCustomAttributes(typeof(KnownTypeAttribute), true);
            for (int i = 0; i < attrs.Length; i++)
            {
                KnownTypeAttribute kt = (KnownTypeAttribute)attrs [i];
                TryRegister(kt.Type);
            }

            return(ret);
        }
コード例 #2
0
ファイル: KnownTypeCollection.cs プロジェクト: nuxleus/mono
        private SharedContractMap RegisterContract(Type type)
        {
            QName qname = GetContractQName(type);

            if (qname == null)
            {
                return(null);
            }
            CheckStandardQName(qname);
            if (FindUserMap(qname) != null)
            {
                throw new InvalidOperationException(String.Format("There is already a registered type for XML name {0}", qname));
            }

            SharedContractMap ret = new SharedContractMap(type, qname, this);

            contracts.Add(ret);
            ret.Initialize();

            if (type.BaseType != typeof(object))
            {
                TryRegister(type.BaseType);
                if (!FindUserMap(type.BaseType).IsContractAllowedType)
                {
                    throw new InvalidDataContractException(String.Format("To be serializable by data contract, type '{0}' cannot inherit from non-contract and non-Serializable type '{1}'", type, type.BaseType));
                }
            }

            object [] attrs = type.GetCustomAttributes(typeof(KnownTypeAttribute), true);
            for (int i = 0; i < attrs.Length; i++)
            {
                KnownTypeAttribute kt = (KnownTypeAttribute)attrs [i];
                foreach (var t in kt.GetTypes(type))
                {
                    TryRegister(t);
                }
            }

            return(ret);
        }