GetXmlTypeInfo() static private method

static private GetXmlTypeInfo ( Type type, XmlQualifiedName &stableName, XmlSchemaType &xsdType, bool &hasRoot ) : void
type System.Type
stableName System.Xml.XmlQualifiedName
xsdType System.Xml.Schema.XmlSchemaType
hasRoot bool
return void
            internal XmlDataContractCriticalHelper(
                [DynamicallyAccessedMembers(ClassDataContract.DataContractPreserveMemberTypes)]
                Type type) : base(type)
            {
                if (type.IsDefined(Globals.TypeOfDataContractAttribute, false))
                {
                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IXmlSerializableCannotHaveDataContract, DataContract.GetClrTypeFullName(type))));
                }
                if (type.IsDefined(Globals.TypeOfCollectionDataContractAttribute, false))
                {
                    throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IXmlSerializableCannotHaveCollectionDataContract, DataContract.GetClrTypeFullName(type))));
                }
                XmlSchemaType?   xsdType;
                bool             hasRoot;
                XmlQualifiedName stableName;

                SchemaExporter.GetXmlTypeInfo(type, out stableName, out xsdType, out hasRoot);
                this.StableName = stableName;
                this.HasRoot    = hasRoot;
                XmlDictionary dictionary = new XmlDictionary();

                this.Name      = dictionary.Add(StableName.Name);
                this.Namespace = dictionary.Add(StableName.Namespace);
                object[]? xmlRootAttributes = (UnderlyingType == null) ? null : UnderlyingType.GetCustomAttributes(Globals.TypeOfXmlRootAttribute, false).ToArray();
                if (xmlRootAttributes == null || xmlRootAttributes.Length == 0)
                {
                    if (hasRoot)
                    {
                        _topLevelElementName       = Name;
                        _topLevelElementNamespace  = (this.StableName.Namespace == Globals.SchemaNamespace) ? DictionaryGlobals.EmptyString : Namespace;
                        _isTopLevelElementNullable = true;
                    }
                }
                else
                {
                    if (hasRoot)
                    {
                        XmlRootAttribute xmlRootAttribute = (XmlRootAttribute)xmlRootAttributes[0];
                        _isTopLevelElementNullable = xmlRootAttribute.IsNullable;
                        string elementName = xmlRootAttribute.ElementName;
                        _topLevelElementName = (elementName == null || elementName.Length == 0) ? Name : dictionary.Add(DataContract.EncodeLocalName(elementName));
                        string?elementNs = xmlRootAttribute.Namespace;
                        _topLevelElementNamespace = (elementNs == null || elementNs.Length == 0) ? DictionaryGlobals.EmptyString : dictionary.Add(elementNs);
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.IsAnyCannotHaveXmlRoot, DataContract.GetClrTypeFullName(UnderlyingType !))));
                    }
                }
            }
Beispiel #2
0
            internal XmlDataContractCriticalHelper(Type type) : base(type)
            {
                XmlSchemaType    type2;
                bool             flag;
                XmlQualifiedName name;

                if (type.IsDefined(Globals.TypeOfDataContractAttribute, false))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.Runtime.Serialization.SR.GetString("IXmlSerializableCannotHaveDataContract", new object[] { DataContract.GetClrTypeFullName(type) })));
                }
                if (type.IsDefined(Globals.TypeOfCollectionDataContractAttribute, false))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.Runtime.Serialization.SR.GetString("IXmlSerializableCannotHaveCollectionDataContract", new object[] { DataContract.GetClrTypeFullName(type) })));
                }
                SchemaExporter.GetXmlTypeInfo(type, out name, out type2, out flag);
                base.StableName = name;
                this.XsdType    = type2;
                this.HasRoot    = flag;
                XmlDictionary dictionary = new XmlDictionary();

                base.Name      = dictionary.Add(base.StableName.Name);
                base.Namespace = dictionary.Add(base.StableName.Namespace);
                object[] objArray = (base.UnderlyingType == null) ? null : base.UnderlyingType.GetCustomAttributes(Globals.TypeOfXmlRootAttribute, false);
                if ((objArray == null) || (objArray.Length == 0))
                {
                    if (flag)
                    {
                        this.topLevelElementName       = base.Name;
                        this.topLevelElementNamespace  = (base.StableName.Namespace == "http://www.w3.org/2001/XMLSchema") ? DictionaryGlobals.EmptyString : base.Namespace;
                        this.isTopLevelElementNullable = true;
                    }
                }
                else
                {
                    if (!flag)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(System.Runtime.Serialization.SR.GetString("IsAnyCannotHaveXmlRoot", new object[] { DataContract.GetClrTypeFullName(base.UnderlyingType) })));
                    }
                    XmlRootAttribute attribute = (XmlRootAttribute)objArray[0];
                    this.isTopLevelElementNullable = attribute.IsNullable;
                    string elementName = attribute.ElementName;
                    this.topLevelElementName = ((elementName == null) || (elementName.Length == 0)) ? base.Name : dictionary.Add(DataContract.EncodeLocalName(elementName));
                    string str2 = attribute.Namespace;
                    this.topLevelElementNamespace = ((str2 == null) || (str2.Length == 0)) ? DictionaryGlobals.EmptyString : dictionary.Add(str2);
                }
            }