Ejemplo n.º 1
0
		public XmlSchemaAttribute()
		{
			//LAMESPEC: Docs says the default is optional.
			//Whereas the MS implementation has default None.
			form	= XmlSchemaForm.None;
			use		= XmlSchemaUse.None;
			schemaTypeName	= XmlQualifiedName.Empty;
			qualifiedName	= XmlQualifiedName.Empty;
			refName			= XmlQualifiedName.Empty;
		}
Ejemplo n.º 2
0
        public virtual void ClassAttributeFieldCode(StreamWriter outStream, string dotNetDatatype, string xsdDatatype, string fieldName, string dotnetFieldName, XmlSchemaForm attributeFormDefault, bool isSchemaEnumerationType, string ns)
        {
            outStream.WriteLine();
            string str = fieldName;
            string str2 = ReplaceInvalidChars(dotnetFieldName);
            string str3 = this.CheckForKeywords(dotnetFieldName);
            string str4 = this.ConvertSystemDatatype(dotNetDatatype);
            string str5 = "";
            string str6 = "";
            if ((attributeFormDefault == XmlSchemaForm.Qualified) || (attributeFormDefault == XmlSchemaForm.Unqualified))
            {
                str6 = ",Form" + this.AttributeAssignmentOperator + "XmlSchemaForm." + attributeFormDefault.ToString();
                str5 = this.CalculateNamespace(this.schemaTargetNamespace, ns, dotNetDatatype == "System.Xml.XmlAttribute[]");
            }
            if (xsdDatatype == "anyType")
            {
                xsdDatatype = "";
            }
            else if (xsdDatatype != "")
            {
                xsdDatatype = ",DataType" + this.AttributeAssignmentOperator + "\"" + xsdDatatype + "\"";
            }
            switch (dotNetDatatype)
            {
                case "System.String":
                case "System.Byte[]":
                case "System.Object":
                case "System.Xml.XmlQualifiedName":
                    outStream.WriteLine(this.AttributeObjectTemplate, new object[] { str2, str4, str, str6, xsdDatatype, str3, str5, hiddenMemberPrefix });
                    break;

                case "System.Xml.XmlAttribute[]":
                    outStream.WriteLine(this.AttributeAnyTemplate, new object[] { str2, str4, str, str6, xsdDatatype, str3, str5, hiddenMemberPrefix });
                    break;

                case "System.DateTime":
                    outStream.WriteLine(this.AttributeDateTimeTemplate, new object[] { str2, str4, str, str6, xsdDatatype, str3, str5, hiddenMemberPrefix });
                    break;

                default:
                    if (str4 == "string")
                    {
                        outStream.WriteLine(this.AttributeObjectTemplate, new object[] { str2, str4, str, str6, xsdDatatype, str3, str5, hiddenMemberPrefix });
                    }
                    else
                    {
                        outStream.WriteLine(this.AttributeValueTypeTemplate, new object[] { str2, str4, str, str6, xsdDatatype, str3, str5, hiddenMemberPrefix });
                    }
                    break;
            }
        }
Ejemplo n.º 3
0
		public static void AssertElementEx (XmlSchemaElement element,
			XmlSchemaDerivationMethod block, XmlSchemaDerivationMethod final,
			string defaultValue, string fixedValue,
			XmlSchemaForm form, bool isAbstract, bool isNillable,
			XmlQualifiedName substGroup)
		{
			Assert.IsNotNull (element);
			Assert.AreEqual (block, element.Block);
			Assert.AreEqual (final, element.Final);
			Assert.AreEqual (defaultValue, element.DefaultValue);
			Assert.AreEqual (fixedValue, element.FixedValue);
			Assert.AreEqual (form, element.Form);
			Assert.AreEqual (isAbstract, element.IsAbstract);
			Assert.AreEqual (isNillable, element.IsNillable);
			Assert.AreEqual (substGroup, element.SubstitutionGroup);
		}
Ejemplo n.º 4
0
		public XmlSchema ()
		{
			attributeFormDefault= XmlSchemaForm.None;
			blockDefault = XmlSchemaDerivationMethod.None;
			elementFormDefault = XmlSchemaForm.None;
			finalDefault = XmlSchemaDerivationMethod.None;
			includes = new XmlSchemaObjectCollection();
			isCompiled = false;
			items = new XmlSchemaObjectCollection();
			attributeGroups = new XmlSchemaObjectTable();
			attributes = new XmlSchemaObjectTable();
			elements = new XmlSchemaObjectTable();
			groups = new XmlSchemaObjectTable();
			notations = new XmlSchemaObjectTable();
			schemaTypes = new XmlSchemaObjectTable();
		}
Ejemplo n.º 5
0
 public XmlSchema()
 {
     attributeFormDefault = XmlSchemaForm.None;
     blockDefault         = XmlSchemaDerivationMethod.None;
     elementFormDefault   = XmlSchemaForm.None;
     finalDefault         = XmlSchemaDerivationMethod.None;
     includes             = new XmlSchemaObjectCollection();
     isCompiled           = false;
     items            = new XmlSchemaObjectCollection();
     attributeGroups  = new XmlSchemaObjectTable();
     attributes       = new XmlSchemaObjectTable();
     elements         = new XmlSchemaObjectTable();
     groups           = new XmlSchemaObjectTable();
     notations        = new XmlSchemaObjectTable();
     schemaTypes      = new XmlSchemaObjectTable();
     named_identities = new XmlSchemaObjectTable();
     ids = new Hashtable();
     compilationItems = new XmlSchemaObjectCollection();
 }
		internal XmlMemberMapping (string memberName, string defaultNamespace, XmlTypeMapMember mapMem, bool encodedFormat)
		{
			_mapMember = mapMem;
			_memberName = memberName;

			if (mapMem is XmlTypeMapMemberAnyElement)
			{
				XmlTypeMapMemberAnyElement anyelem = (XmlTypeMapMemberAnyElement) mapMem;
				XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) anyelem.ElementInfo[anyelem.ElementInfo.Count-1];
				_elementName = info.ElementName;
				_namespace = info.Namespace;
				if (info.MappedType != null) _typeNamespace = info.MappedType.Namespace;
				else _typeNamespace = "";
			}
			else if (mapMem is XmlTypeMapMemberElement)
			{
				XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) ((XmlTypeMapMemberElement)mapMem).ElementInfo[0];
				_elementName = info.ElementName;
				if (encodedFormat)
				{
					_namespace = defaultNamespace;
					if (info.MappedType != null) _typeNamespace = "";
					else _typeNamespace = info.DataTypeNamespace;
				}
				else
				{
					_namespace = info.Namespace;
					if (info.MappedType != null) _typeNamespace = info.MappedType.Namespace;
					else _typeNamespace = "";
					_form = info.Form;
				}
			}
			else
			{
				_elementName = _memberName;
				_namespace = "";
			}
			
			if (_form == XmlSchemaForm.None) 
				_form = XmlSchemaForm.Qualified;
		}
Ejemplo n.º 7
0
        public static XmlSchemaForm ReadFormAttribute(XmlReader reader, out Exception innerExcpetion)
        {
            innerExcpetion = null;
            XmlSchemaForm result = XmlSchemaForm.None;
            string        value  = reader.Value;

            if (value != null)
            {
                if (XmlSchemaUtil.< > f__switch$map39 == null)
                {
                    XmlSchemaUtil.< > f__switch$map39 = new Dictionary <string, int>(2)
                    {
                        {
                            "qualified",
                            0
                        },
                        {
                            "unqualified",
                            1
                        }
                    };
                }
                int num;
                if (XmlSchemaUtil.< > f__switch$map39.TryGetValue(value, out num))
                {
                    if (num == 0)
                    {
                        return(XmlSchemaForm.Qualified);
                    }
                    if (num == 1)
                    {
                        return(XmlSchemaForm.Unqualified);
                    }
                }
            }
            innerExcpetion = new Exception("only qualified or unqulified is a valid value");
            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add a field to the class that will persist itself to an element -- who can have children (ComplexType)
        /// </summary>
        /// <param name="outStream"></param>
        /// <param name="elementName">Name attribute on a xsd:element.</element></param>
        /// <param name="dupElementName">Rename of the attribute on the xsd:element in case of duplicates in the xsd</element></param>
        /// <param name="dotnetTypeName">.NET class being referenced</param>
        /// <param name="parentContainerClassName">Owner class</param>
        /// <param name="fieldOccurs">maxOccurs on the field from XSD</param>
        /// <param name="particleOccurs">maxOccurs on the particle from XSD if the field is an instance</param>
        /// <param name="elementFormDefault">whether the XML attribute name generated by the XmlSerializer is qualified</param>
        /// <param name="isElementNullable">Set the IsNullable element paramter = true, causing xsi:nil="true" for null elements</param>
        /// <param name="isAbstract">complex type is marked as abstract, so it cannot be created</param>
        public virtual void ClassComplexTypeFieldCode(GeneratorStream generator, String elementName, string dupElementName,
                                                      String dotnetTypeName, String collectionContainedType, String parentContainerClassName, decimal fieldOccurs, decimal particleOccurs,
                                                      XmlSchemaForm elementFormDefault, string ns, bool isElementNullable, bool isAbstract, String default_value, bool is_required)
        {
            string fieldName1 = ReplaceInvalidChars(dupElementName);
            string fieldName2 = CheckForKeywords(fieldName1);
            string fieldType1 = CheckForKeywords(dotnetTypeName);
            string fieldType2 = ReplaceInvalidChars(dotnetTypeName);

            collectionContainedType = CheckForKeywords(collectionContainedType);

            string nameSpace  = "";
            string schemaForm = "";

            if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified)
            {
                schemaForm = ",Form" + AttributeAssignmentOperator + "XmlSchemaForm." + elementFormDefault.ToString();
                nameSpace  = CalculateNamespace(schemaTargetNamespace, ns, false);
            }

            if (particleOccurs > 1 || fieldOccurs > 1)
            {
                generator.put_FieldCollectionTemplate(collectionContainedType, fieldName1, dupElementName, default_value, is_required);
                //outStream.WriteLine(FieldCollectionTemplate, fieldType2, fieldType1, elementName, schemaForm, fieldName1, "", nameSpace,
                //    hiddenMemberPrefix, collectionSuffix, isElementNullable.ToString().ToLower(), collectionContainedType);
            }
            else if (isAbstract)
            {
                //outStream.WriteLine(FieldAbstractClassTemplate, fieldName1, fieldType1, elementName, schemaForm, fieldName2, nameSpace, hiddenMemberPrefix,
                //    isElementNullable.ToString().ToLower());
            }
            else
            {
                generator.put_FieldClassTemplate(fieldType1, fieldName1, dupElementName, default_value, is_required);
                //outStream.WriteLine(FieldClassTemplate, fieldName1, fieldType1, elementName, schemaForm, fieldName2, nameSpace, hiddenMemberPrefix,
                //    isElementNullable.ToString().ToLower());
            }
        }
Ejemplo n.º 9
0
 private void SetSchemaDefaults(XmlSchema schema) {
     if (schema.BlockDefault == XmlSchemaDerivationMethod.All) {
         this.blockDefault = XmlSchemaDerivationMethod.All;
     }
     else if (schema.BlockDefault == XmlSchemaDerivationMethod.None) {
         this.blockDefault = XmlSchemaDerivationMethod.Empty;
     }
     else {
         if ((schema.BlockDefault & ~schemaBlockDefaultAllowed) != 0) {
             SendValidationEvent(Res.Sch_InvalidBlockDefaultValue, schema);
         }
         this.blockDefault = schema.BlockDefault & schemaBlockDefaultAllowed;
     }
     if (schema.FinalDefault == XmlSchemaDerivationMethod.All) {
         this.finalDefault = XmlSchemaDerivationMethod.All;
     }
     else if (schema.FinalDefault == XmlSchemaDerivationMethod.None) {
         this.finalDefault = XmlSchemaDerivationMethod.Empty;
     }
     else {
         if ((schema.FinalDefault & ~schemaFinalDefaultAllowed) != 0) {
             SendValidationEvent(Res.Sch_InvalidFinalDefaultValue, schema);
         }
         this.finalDefault = schema.FinalDefault & schemaFinalDefaultAllowed;
     }
     this.elementFormDefault = schema.ElementFormDefault;
     if (this.elementFormDefault == XmlSchemaForm.None) {
         this.elementFormDefault = XmlSchemaForm.Unqualified;
     }
     this.attributeFormDefault = schema.AttributeFormDefault;
     if (this.attributeFormDefault == XmlSchemaForm.None) {
         this.attributeFormDefault = XmlSchemaForm.Unqualified;
     }
 }
Ejemplo n.º 10
0
        internal XmlMemberMapping(string memberName, string defaultNamespace, XmlTypeMapMember mapMem, bool encodedFormat)
        {
            _mapMember  = mapMem;
            _memberName = memberName;

            if (mapMem is XmlTypeMapMemberAnyElement)
            {
                XmlTypeMapMemberAnyElement anyelem = (XmlTypeMapMemberAnyElement)mapMem;
                XmlTypeMapElementInfo      info    = (XmlTypeMapElementInfo)anyelem.ElementInfo[anyelem.ElementInfo.Count - 1];
                _elementName = info.ElementName;
                _namespace   = info.Namespace;
                if (info.MappedType != null)
                {
                    _typeNamespace = info.MappedType.Namespace;
                }
                else
                {
                    _typeNamespace = "";
                }
            }
            else if (mapMem is XmlTypeMapMemberElement)
            {
                XmlTypeMapElementInfo info = (XmlTypeMapElementInfo)((XmlTypeMapMemberElement)mapMem).ElementInfo[0];
                _elementName = info.ElementName;
                if (encodedFormat)
                {
                    _namespace = defaultNamespace;
                    if (info.MappedType != null)
                    {
                        _typeNamespace = "";
                    }
                    else
                    {
                        _typeNamespace = info.DataTypeNamespace;
                    }
                }
                else
                {
                    _namespace = info.Namespace;
                    if (info.MappedType != null)
                    {
                        _typeNamespace = info.MappedType.Namespace;
                    }
                    else
                    {
                        _typeNamespace = "";
                    }
                    _form = info.Form;
                }
            }
            else
            {
                _elementName = _memberName;
                _namespace   = "";
            }

            if (_form == XmlSchemaForm.None)
            {
                _form = XmlSchemaForm.Qualified;
            }
        }
Ejemplo n.º 11
0
        public override void ClassHeaderCode(GeneratorStream generator, string dotnetClassName, string elementName,
                                             string complexTypeBaseClass, bool baseIsAbstract, bool isSchemaType, bool isAbstract, bool isLocalComplexType, Hashtable enumerableClasses,
                                             string ns, XmlSchemaForm elementFormDefault, string annotation, bool isElementNullable, ArrayList xmlIncludedClasses,
                                             bool globalElementAndSchemaTypeHaveSameName)
        {
            string nameSpace = "";

            if (isSchemaType)
            {
                if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified)
                {
                    nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
                }
                if (globalElementAndSchemaTypeHaveSameName)
                {
                    //outStream.WriteLine("\t[XmlRoot(ElementName=\"{0}\"{1},IsNullable={2}),Serializable]",
                    //    elementName, nameSpace, isElementNullable.ToString().ToLower());
                    //outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1})]",
                    //    dotnetClassName, nameSpace);
                }
                else
                {
                    //outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1}),Serializable]", dotnetClassName, nameSpace);
                }
            }
            else if (isLocalComplexType)
            {
                if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified)
                {
                    nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
                }
                //outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1}),Serializable]",
                //    dotnetClassName, nameSpace);
            }
            else
            {
                // possible root node element -- so put namespace on the element if targetNamesapce has been set
                nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
                //outStream.WriteLine("\t//MAIN_CLASS");
                //outStream.WriteLine("\t[XmlRoot(ElementName=\"{0}\"{1},IsNullable={2}),Serializable]",
                //    elementName, nameSpace, isElementNullable.ToString().ToLower());
            }

            // Add necessary XmlInludes for abstract derived types used in the class
            foreach (string xmlIncludeClass in xmlIncludedClasses)
            {
                //outStream.WriteLine("\t[XmlInclude(typeof({0}))]", CheckForKeywords(xmlIncludeClass));
            }

            string className = CheckForKeywords(dotnetClassName);

            // outStream.WriteLine("\t//CLASS");

            //outStream.Write("\t{1}{2}struct {0}", className, isAbstract ? "abstract " : "", partialClasses ? PartialKeyword : "");

            // setup inheritance for <xsd:extension base="class">
            string inheritance = String.Empty;

            if (complexTypeBaseClass != null && complexTypeBaseClass != "")
            {
                inheritance = CheckForKeywords(complexTypeBaseClass);
            }
            generator.begin_class(className, isAbstract ? "abstract " : "", inheritance);
            //outStream.WriteLine();
            //outStream.WriteLine("\t{");

            // setup enumerability over a contained collection
            if (enumerableClasses.ContainsKey(dotnetClassName))
            {
                ArrayList values         = (ArrayList)enumerableClasses[dotnetClassName];
                string    collectionName = (string)values[0];
                collectionName = ReplaceInvalidChars(collectionName);
                //outStream.WriteLine(ClassEnumerabilityTemplate, collectionName,
                //    ConvertSystemDatatype((string)values[1]), collectionSuffix, hiddenMemberPrefix);
            }
        }
 static void CheckForm(XmlSchemaForm form, bool isQualified) {
     if (isQualified && form == XmlSchemaForm.Unqualified) throw new InvalidOperationException(Res.GetString(Res.XmlInvalidFormUnqualified));
 }
Ejemplo n.º 13
0
        void CreateArrayElementsFromAttributes(ArrayMapping arrayMapping, XmlArrayItemAttributes attributes, Type arrayElementType, string arrayElementNs, XmlSchemaForm form) {
            NameTable arrayItemElements = new NameTable();   // xmlelementname + xmlns -> ElementAccessor

            for (int i = 0; attributes != null && i < attributes.Count; i++) {
                XmlArrayItemAttribute xmlArrayItem = attributes[i];
                if (xmlArrayItem.NestingLevel != arrayNestingLevel)
                    continue;
                Type targetType = xmlArrayItem.Type != null ? xmlArrayItem.Type : arrayElementType;
                TypeDesc targetTypeDesc = typeScope.GetTypeDesc(targetType);
                ElementAccessor arrayItemElement = new ElementAccessor();
                arrayItemElement.Namespace = xmlArrayItem.Namespace == null ? arrayElementNs : xmlArrayItem.Namespace;
                arrayItemElement.Mapping = ImportTypeMapping(modelScope.GetTypeModel(targetType), arrayItemElement.Namespace, ImportContext.Element, xmlArrayItem.DataType);
                arrayItemElement.Name = Accessor.EscapeName(xmlArrayItem.ElementName.Length == 0 ? arrayItemElement.Mapping.TypeName : xmlArrayItem.ElementName, false);
                arrayItemElement.IsNullable = xmlArrayItem.IsNullableSpecified ? xmlArrayItem.IsNullable : targetTypeDesc.IsNullable;
                arrayItemElement.Form = xmlArrayItem.Form == XmlSchemaForm.None ? form : xmlArrayItem.Form;
                CheckForm(arrayItemElement.Form, arrayElementNs != arrayItemElement.Namespace);
                CheckNullable(arrayItemElement.IsNullable, targetTypeDesc);
                AddUniqueAccessor(arrayItemElements, arrayItemElement);
            }
            arrayMapping.Elements = (ElementAccessor[])arrayItemElements.ToArray(typeof(ElementAccessor));
        }
        void ImportAccessorMapping(MemberMapping accessor, FieldModel model, SoapAttributes a, string ns, XmlSchemaForm form) {
            Type accessorType = model.FieldType;
            string accessorName = model.Name;
            accessor.TypeDesc = typeScope.GetTypeDesc(accessorType);
            if (accessor.TypeDesc.IsVoid) {
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidVoid));
            }

            SoapAttributeFlags flags = a.SoapFlags;
            if ((flags & SoapAttributeFlags.Attribute) == SoapAttributeFlags.Attribute) {
                if (!accessor.TypeDesc.IsPrimitive && !accessor.TypeDesc.IsEnum)
                    throw new InvalidOperationException(Res.GetString(Res.XmlIllegalSoapAttribute, accessorName, accessor.TypeDesc.FullName));

                if ((flags & SoapAttributeFlags.Attribute) != flags)
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidElementAttribute));
                
                AttributeAccessor attribute = new AttributeAccessor();
                attribute.Name = Accessor.EscapeQName(a.SoapAttribute == null || a.SoapAttribute.AttributeName.Length == 0 ? accessorName : a.SoapAttribute.AttributeName);
                attribute.Namespace = a.SoapAttribute == null || a.SoapAttribute.Namespace == null ? ns : a.SoapAttribute.Namespace;
                attribute.Form = XmlSchemaForm.Qualified; // attributes are always qualified since they're only used for encoded soap headers
                attribute.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), (a.SoapAttribute == null ? String.Empty : a.SoapAttribute.DataType));
                attribute.Default = GetDefaultValue(model.FieldTypeDesc, a);
                accessor.Attribute = attribute;
                accessor.Elements = new ElementAccessor[0];
            }
            else {
                if ((flags & SoapAttributeFlags.Element) != flags)
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidElementAttribute));

                ElementAccessor element = new ElementAccessor();
                element.IsSoap = true;
                element.Name = XmlConvert.EncodeLocalName(a.SoapElement == null || a.SoapElement.ElementName.Length == 0 ? accessorName : a.SoapElement.ElementName);
                element.Namespace = ns;
                element.Form = form;
                element.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), (a.SoapElement == null ? String.Empty : a.SoapElement.DataType));
                if (a.SoapElement != null)
                    element.IsNullable = a.SoapElement.IsNullable;
                accessor.Elements = new ElementAccessor[] { element };
            }
        }
Ejemplo n.º 15
0
 void ExportElement(CodeAttributeDeclarationCollection metadata, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, bool isNullable, XmlSchemaForm form)
 {
     ExportMetadata(metadata, typeof(XmlElementAttribute), name, ns, typeDesc, dataTypeDesc, isNullable ? (object)true : null, form, 0);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Add the class keyword and inheritance relationship if necessary
 /// </summary>
 /// <param name="outStream">Out file</param>
 /// <param name="dotnetClassName">Classname to be used in code</param>
 /// <param name="elementName">Xml element for the class</param>
 /// <param name="complexTypeBaseClass">Base class</param>
 /// <param name="baseIsAbstract">Base class is an abstract type</param>
 /// <param name="isSchemaType">Is a global ComplexType defined at the schema level</param>
 /// <param name="isAbstract">Is the complexType an Abstract type -- marked with abstract="true"</param>
 /// <param name="isLocalComplexType">Locally scoped complexType (not a child of schema tag)</schema></param>
 /// <param name="enumerableClasses">List of enumerable classes</param>
 /// <param name="ns">namespace</param>
 /// <param name="elementFormDefault">whether the xml element for the class will be namespace qualified</param>
 /// <param name="annotation">complexType annotation</param>
 /// <param name="isElementNullable">Set the IsNullable element paramter = true, causing xsi:nil="true" for null elements</param>
 /// <param name="xmlIncludedClasses">List of classes to put in XmlIncludeAttributes -- needed for abstract ComplexTypes</param>
 /// <param name="globalElementAndSchemaTypeHaveSameName">For global schema types where an existing global element also has the same name</param>
 public abstract void ClassHeaderCode(GeneratorStream generator, string dotnetClassName, string elementName,
                                      string complexTypeBaseClass, bool baseIsAbstract, bool isSchemaType, bool isAbstract, bool isLocalComplexType, Hashtable enumerableClasses,
                                      string ns, XmlSchemaForm elementFormDefault, string annotation, bool isElementNullable, ArrayList xmlIncludedClasses,
                                      bool globalElementAndSchemaTypeHaveSameName);
Ejemplo n.º 17
0
        /// <summary>
        /// Add a field to the class that will persist itself to an element (element with no children)
        /// </summary>
        /// <param name="outStream"></param>
        /// <param name="dotNetDatatype">.NET System datatype</param>
        /// <param name="xsdDatatype">XSD equivelent datatype</param>
        /// <param name="fieldName">Name of the element that will be a new field in code</param>
        /// <param name="dotnetFieldName">Name of the .net class field -- different from fieldName if duplicates occur</param>
        /// <param name="fieldOccurs">maxOccurs on the field from XSD</param>
        /// <param name="particleOccurs">maxOccurs on the particle from XSD if the field is an instance</param>
        /// <param name="elementFormDefault">whether the XML attribute name generated by the XmlSerializer is qualified</param>
        /// <param name="isSchemaEnumerationType">some languages like MC++ need to perform special logic if the field's type is an enumeration</param>
        /// <param name="ns">element namespace</param>
        /// <param name="isElementNullable">Set the IsNullable element paramter = true, causing xsi:nil="true" for null elements</param>
        public virtual void ClassElementFieldCode(GeneratorStream generator, string dotNetDatatype, string xsdDatatype,
                                                  string fieldName, string dotnetFieldName, decimal fieldOccurs, decimal particleOccurs, XmlSchemaForm elementFormDefault,
                                                  bool isSchemaEnumerationType, string ns, bool isElementNullable, String default_value, bool is_required)
        {
            string elementName = fieldName;
            string fieldName1  = ReplaceInvalidChars(dotnetFieldName);
            string fieldName2  = CheckForKeywords(dotnetFieldName);
            string fieldType   = ConvertSystemDatatype(dotNetDatatype);

            string nameSpace  = "";
            string schemaForm = "";

            if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified)
            {
                schemaForm = ",Form" + AttributeAssignmentOperator + "XmlSchemaForm." + elementFormDefault.ToString();
                nameSpace  = CalculateNamespace(schemaTargetNamespace, ns, dotNetDatatype == "System.Xml.XmlElement");

                // special case for <xs:any> elements
                // <xs:any> has XmlElement dotnet type.
                if (dotNetDatatype == "System.Xml.XmlElement" && nameSpace != "")
                {
                    nameSpace = "Name" + AttributeAssignmentOperator + "\"" + fieldName2 + "\"" + nameSpace;
                }
            }

            if (xsdDatatype == "anyType")
            {
                xsdDatatype = "";
            }
            else if (xsdDatatype != "")
            {
                xsdDatatype = ",DataType" + AttributeAssignmentOperator + "\"" + xsdDatatype + "\"";
            }

            if (particleOccurs > 1 || fieldOccurs > 1)
            {
                if (dotNetDatatype == "System.Xml.XmlElement")
                {
                    //outStream.WriteLine(ElementAnyMaxOccursTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                    //    hiddenMemberPrefix, isElementNullable.ToString().ToLower());
                }
                else
                {
                    generator.put_FieldCollectionTemplate(fieldType, elementName, elementName, default_value, is_required);
                    //outStream.WriteLine(FieldCollectionTemplate, fieldName1, fieldType, elementName, schemaForm, fieldName1, xsdDatatype, nameSpace,
                    //    hiddenMemberPrefix, collectionSuffix, isElementNullable.ToString().ToLower(), fieldType);
                }
            }
            else
            {
                switch (dotNetDatatype)
                {
                // object type
                case "System.String":
                case "System.Byte[]":
                case "System.Object":
                case "System.Xml.XmlQualifiedName":
                    generator.put_ElementObjectTemplate(fieldType, fieldName1, elementName, default_value, is_required);
                    //outStream.WriteLine(ElementObjectTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                    //    hiddenMemberPrefix, isElementNullable.ToString().ToLower());
                    break;

                // special xsd:any
                case "System.Xml.XmlElement":
                    // assuming properly formatted nameSpace from above with Name and Namespace parameters
                    //outStream.WriteLine(ElementAnyTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                    //    hiddenMemberPrefix, isElementNullable.ToString().ToLower());
                    break;

                // value type
                case "System.DateTime":
                    //outStream.WriteLine(ElementDateTimeTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                    //    hiddenMemberPrefix);
                    break;

                default:
                    if (fieldType == "string")       // value types like System.Uri
                    {
                        generator.put_ElementObjectTemplate(fieldType, fieldName1, elementName, default_value, is_required);
                    }
                    //outStream.WriteLine(ElementObjectTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                    //    hiddenMemberPrefix, isElementNullable.ToString().ToLower());
                    else
                    if (fieldType.StartsWith("OLI_LU_"))
                    {
                        generator.put_ElementValueTypeTemplate("int", fieldName1, elementName, default_value, is_required);
                    }
                    //outStream.WriteLine(ElementValueTypeTemplate, fieldName1, "int", elementName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                    //hiddenMemberPrefix);
                    else
                    {
                        generator.put_ElementValueTypeTemplate(fieldType, fieldName1, elementName, default_value, is_required);
                    }
                    //outStream.WriteLine(ElementValueTypeTemplate, fieldName1, fieldType, elementName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                    //hiddenMemberPrefix);
                    break;
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Add a field to the class that will persist itself to an attrbute
        /// </summary>
        /// <param name="outStream"></param>
        /// <param name="dotNetDatatype">.NET System datatype</param>
        /// <param name="xsdDatatype">XSD equivelent datatype</param>
        /// <param name="fieldName">Name of the attribute that will be a new field in code</param>
        /// <param name="dotnetFieldName">Name of the .net class field -- different from fieldName if duplicates occur</param>
        /// <param name="attributeFormDefault">whether the XML attribute name generated by the XmlSerializer is qualified</param>
        /// <param name="isSchemaEnumerationType">some languages like MC++ need to perform special logic if the field's type is an enumeration</param>
        /// <param name="ns">attribute namesapce</param>
        public virtual void ClassAttributeFieldCode(GeneratorStream generator, string dotNetDatatype, string xsdDatatype,
                                                    string fieldName, string dotnetFieldName, XmlSchemaForm attributeFormDefault, bool isSchemaEnumerationType, string ns, string default_value, bool is_required)
        {
            string attributeName = fieldName;
            string fieldName1    = ReplaceInvalidChars(dotnetFieldName);
            string fieldName2    = CheckForKeywords(dotnetFieldName);
            string fieldType     = ConvertSystemDatatype(dotNetDatatype);

            string nameSpace  = "";
            string schemaForm = "";

            if (attributeFormDefault == XmlSchemaForm.Qualified || attributeFormDefault == XmlSchemaForm.Unqualified)
            {
                schemaForm = ",Form" + AttributeAssignmentOperator + "XmlSchemaForm." + attributeFormDefault.ToString();
                nameSpace  = CalculateNamespace(schemaTargetNamespace, ns, dotNetDatatype == "System.Xml.XmlAttribute[]");
            }

            if (xsdDatatype == "anyType")
            {
                xsdDatatype = "";
            }
            else if (xsdDatatype != "")
            {
                xsdDatatype = ",DataType" + AttributeAssignmentOperator + "\"" + xsdDatatype + "\"";
            }

            switch (dotNetDatatype)
            {
            // object type
            case "System.String":
            case "System.Byte[]":
            case "System.Object":
            case "System.Xml.XmlQualifiedName":
                generator.put_AttributeObjectTemplate(fieldType, fieldName1, attributeName, default_value, is_required);
                //outStream.WriteLine(AttributeObjectTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                //    hiddenMemberPrefix);
                break;

            // special xsd:any
            case "System.Xml.XmlAttribute[]":
                //outStream.WriteLine(AttributeAnyTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                //    hiddenMemberPrefix);
                break;

            // value type
            case "System.DateTime":
                //outStream.WriteLine(AttributeDateTimeTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                //    hiddenMemberPrefix);
                break;

            default:
                if (fieldType == "string")       // value types like System.Uri
                {
                    generator.put_AttributeObjectTemplate(fieldType, fieldName1, attributeName, default_value, is_required);
                }
                //outStream.WriteLine(AttributeObjectTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                //    hiddenMemberPrefix);
                else
                if (fieldType.StartsWith("OLI_LU_"))          // special case for ACORD life
                {
                    generator.put_AttributeValueTypeTemplate("int", fieldName1, attributeName, default_value, is_required);
                }
                //outStream.WriteLine(AttributeValueTypeTemplate, fieldName1, "int", attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                //    hiddenMemberPrefix);
                else
                {
                    generator.put_AttributeValueTypeTemplate(fieldType, fieldName1, attributeName, default_value, is_required);
                }
                //outStream.WriteLine(AttributeValueTypeTemplate, fieldName1, fieldType, attributeName, schemaForm, xsdDatatype, fieldName2, nameSpace,
                //    hiddenMemberPrefix);
                break;
            }
        }
 private void ExportArray(CodeAttributeDeclarationCollection metadata, string name, string ns, bool isNullable, XmlSchemaForm form, int sequenceId)
 {
     this.ExportMetadata(metadata, typeof(XmlArrayAttribute), name, ns, null, null, isNullable ? ((object)true) : null, form, 0, sequenceId);
 }
 private void ExportElement(CodeAttributeDeclarationCollection metadata, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, bool isNullable, XmlSchemaForm form, int sequenceId)
 {
     this.ExportMetadata(metadata, typeof(XmlElementAttribute), name, ns, typeDesc, dataTypeDesc, isNullable ? ((object)true) : null, form, 0, sequenceId);
 }
        private void ExportMetadata(CodeAttributeDeclarationCollection metadata, Type attributeType, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, object isNullable, XmlSchemaForm form, int nestingLevel, int sequenceId)
        {
            CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(attributeType.FullName);

            if (name != null)
            {
                declaration.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(name)));
            }
            if (typeDesc != null)
            {
                if ((((isNullable != null) && ((bool)isNullable)) && (typeDesc.IsValueType && !typeDesc.IsMappedType)) && base.CodeProvider.Supports(GeneratorSupport.GenericTypeReference))
                {
                    declaration.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression("System.Nullable`1[" + typeDesc.FullName + "]")));
                    isNullable = null;
                }
                else
                {
                    declaration.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(typeDesc.FullName)));
                }
            }
            if (form != XmlSchemaForm.None)
            {
                declaration.Arguments.Add(new CodeAttributeArgument("Form", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(XmlSchemaForm).FullName), Enum.Format(typeof(XmlSchemaForm), form, "G"))));
                if (((form == XmlSchemaForm.Unqualified) && (ns != null)) && (ns.Length == 0))
                {
                    ns = null;
                }
            }
            if (ns != null)
            {
                declaration.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
            }
            if (((dataTypeDesc != null) && dataTypeDesc.IsAmbiguousDataType) && !dataTypeDesc.IsMappedType)
            {
                declaration.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(dataTypeDesc.DataType.Name)));
            }
            if (isNullable != null)
            {
                declaration.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression((bool)isNullable)));
            }
            if (nestingLevel > 0)
            {
                declaration.Arguments.Add(new CodeAttributeArgument("NestingLevel", new CodePrimitiveExpression(nestingLevel)));
            }
            if (sequenceId >= 0)
            {
                declaration.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(sequenceId)));
            }
            if ((declaration.Arguments.Count != 0) || (attributeType != typeof(XmlElementAttribute)))
            {
                metadata.Add(declaration);
            }
        }
Ejemplo n.º 22
0
		public override void ClassHeaderCode(StreamWriter outStream, string dotnetClassName, string elementName, 
			string complexTypeBaseClass, bool baseIsAbstract, bool isSchemaType, bool isAbstract, bool isLocalComplexType, Hashtable enumerableClasses, 
			string ns, XmlSchemaForm elementFormDefault, string annotation, bool isElementNullable, ArrayList xmlIncludedClasses,
			bool globalElementAndSchemaTypeHaveSameName)
		{
			outStream.WriteLine();
			outStream.WriteLine();
			
            string nameSpace = "";
			if (isSchemaType)
			{
				if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified) 
				{
					nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
				}
				if (globalElementAndSchemaTypeHaveSameName)
				{
					outStream.WriteLine("\t[XmlRoot(ElementName=\"{0}\"{1},IsNullable={2}),Serializable]", 
						elementName, nameSpace, isElementNullable.ToString().ToLower());
					outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1})]", 
						dotnetClassName, nameSpace);
				}
				else
				{
					outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1}),Serializable]", dotnetClassName, nameSpace);
				}
			}
			else if (isLocalComplexType)
			{
				if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified) 
				{
					nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
				}
				outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1}),Serializable]", 
					dotnetClassName, nameSpace);
			}
			else 
			{
				// possible root node element -- so put namespace on the element if targetNamesapce has been set
				nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
				outStream.WriteLine("\t[XmlRoot(ElementName=\"{0}\"{1},IsNullable={2}),Serializable]", 
					elementName, nameSpace, isElementNullable.ToString().ToLower());
			}

			// Add necessary XmlInludes for abstract derived types used in the class
			foreach (string xmlIncludeClass in xmlIncludedClasses)
			{
				outStream.WriteLine("\t[XmlInclude(typeof({0}))]", CheckForKeywords(xmlIncludeClass));
			}
			
			string className = CheckForKeywords(dotnetClassName);
            outStream.Write("\tpublic {1}{2}class {0}", className, isAbstract ? "abstract " : "", partialClasses ? PartialKeyword : "");

			// setup inheritance for <xsd:extension base="class"> 
			if (complexTypeBaseClass != null && complexTypeBaseClass != "")
				outStream.Write(" : {0}", CheckForKeywords(complexTypeBaseClass));

			outStream.WriteLine();
			outStream.WriteLine("\t{");

			// setup enumerability over a contained collection
			if (enumerableClasses.ContainsKey(dotnetClassName))
			{
				ArrayList values = (ArrayList) enumerableClasses[dotnetClassName];
				string collectionName = (string) values[0];
				collectionName = ReplaceInvalidChars(collectionName);
				outStream.WriteLine(ClassEnumerabilityTemplate, collectionName,
                    ConvertSystemDatatype((string)values[1]), collectionSuffix, hiddenMemberPrefix);
			}
		}
Ejemplo n.º 23
0
 void ExportAttribute(CodeAttributeDeclarationCollection metadata, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, XmlSchemaForm form)
 {
     ExportMetadata(metadata, typeof(XmlAttributeAttribute), name, ns, typeDesc, dataTypeDesc, null, form, 0);
 }
Ejemplo n.º 24
0
		internal void ProcessDecorations()
		{
			if( XmlAttribute != null )
			{
				if( !string.IsNullOrEmpty( XmlAttribute.AttributeName ) )
					_nodeName = XmlAttribute.AttributeName;
				_namespace = XmlAttribute.Namespace;
				Form = XmlAttribute.Form;
				_nodeType = XPathNodeType.Attribute;
			}

			else if( XmlElement != null )
			{
				if( !string.IsNullOrEmpty( XmlElement.ElementName ) )
					_nodeName = XmlElement.ElementName;
				_namespace = XmlElement.Namespace;
				Form = XmlElement.Form;
				_nodeType = XPathNodeType.Element;
				if( typeof( IList ).IsAssignableFrom( Type ) )
					_isTransparent = true;
			}

			else if( XmlAnyElement != null )
			{
				if( !string.IsNullOrEmpty( XmlAnyElement.Name ) )
					_nodeName = XmlAnyElement.Name;
				_namespace = XmlAnyElement.Namespace;
				Form = XmlSchemaForm.Qualified;
/*
				if( _namespace != null )
					Form = XmlSchemaForm.Qualified;
				else
					Form = XmlSchemaForm.Unqualified;
*/
				_nodeType = XPathNodeType.Element;
				_isTransparent = true;

				if( typeof( XmlNode[] ).IsAssignableFrom( Type ) ) 
					Add( new NodePolicyAttribute( typeof( AnyElementXmlNodeArrayNodePolicy )));
			}

			else if( XmlText != null )
			{
				_nodeType = XPathNodeType.Text;
			}

			if( Converter != null )
			{
				base.ConverterType = Converter.ConverterType;
			}
	
			if( Transparent != null )
				_isTransparent = Transparent.IsTransparent;
		}
Ejemplo n.º 25
0
        void ExportMetadata(CodeAttributeDeclarationCollection metadata, Type attributeType, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, object isNullable, XmlSchemaForm form, int nestingLevel)
        {
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType.FullName);

            if (name != null)
            {
                attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(name)));
            }
            if (typeDesc != null)
            {
                CodeIdentifier.CheckValidTypeIdentifier(typeDesc.FullName);
                attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(typeDesc.FullName)));
            }
            if (form != XmlSchemaForm.None)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("Form", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(XmlSchemaForm).FullName), Enum.Format(typeof(XmlSchemaForm), form, "G"))));
            }
            if (ns != null)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
            }
            if (dataTypeDesc != null && dataTypeDesc.IsAmbiguousDataType)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(dataTypeDesc.DataType.Name)));
            }
            if (isNullable != null)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression((bool)isNullable)));
            }
            if (nestingLevel > 0)
            {
                attribute.Arguments.Add(new CodeAttributeArgument("NestingLevel", new CodePrimitiveExpression(nestingLevel)));
            }

            if (attribute.Arguments.Count == 0 && attributeType == typeof(XmlElementAttribute))
            {
                return;
            }
            metadata.Add(attribute);
        }
Ejemplo n.º 26
0
		/// <summary>
		/// Creates a new <see cref="MemberInfo"/> instance.
		/// </summary>
		protected MemberInfo( )
		{
			_nodeName = string.Empty;
			_nodeType = XPathNodeType.Element;
			Form = XmlSchemaForm.None;
		}
Ejemplo n.º 27
0
        public override void ClassHeaderCode(StreamWriter outStream, string dotnetClassName, string elementName,
                                             string complexTypeBaseClass, bool baseIsAbstract, bool isSchemaType, bool isAbstract, bool isLocalComplexType, Hashtable enumerableClasses,
                                             string ns, XmlSchemaForm elementFormDefault, string annotation, bool isElementNullable, ArrayList xmlIncludedClasses,
                                             bool globalElementAndSchemaTypeHaveSameName)
        {
            outStream.WriteLine();
            outStream.WriteLine();
            outStream.WriteLine("\t'--------------------------------------------------");
            outStream.WriteLine("\t'{0} {1}", isSchemaType || isLocalComplexType ? dotnetClassName : elementName,
                                isSchemaType ? "type" : "element");
            outStream.WriteLine("\t'--------------------------------------------------");

            string nameSpace = "";

            if (isSchemaType)
            {
                if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified)
                {
                    nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
                }
                if (globalElementAndSchemaTypeHaveSameName)
                {
                    // possible root node element -- so put namespace on the element if targetNamesapce has been set
                    nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);

                    outStream.WriteLine("\t<XmlRoot(ElementName:=\"{0}\"{1},IsNullable:={2}),Serializable, _",
                                        elementName, nameSpace, isElementNullable.ToString());
                    outStream.Write("\tXmlType(TypeName:=\"{0}\"{1})",
                                    dotnetClassName, nameSpace);
                }
                else
                {
                    outStream.Write("\t<XmlType(TypeName:=\"{0}\"{1}),Serializable", dotnetClassName, nameSpace);
                }
            }
            else if (isLocalComplexType)
            {
                if (elementFormDefault == XmlSchemaForm.Qualified || elementFormDefault == XmlSchemaForm.Unqualified)
                {
                    nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
                }
                outStream.Write("\t<XmlType(TypeName:=\"{0}\"{1}),Serializable",
                                dotnetClassName, nameSpace);
            }
            else
            {
                // possible root node element -- so put namespace on the element if targetNamesapce has been set
                nameSpace = CalculateNamespace(schemaTargetNamespace, ns, false);
                outStream.Write("\t<XmlRoot(ElementName:=\"{0}\"{1},IsNullable:={2}),Serializable",
                                elementName, nameSpace, isElementNullable.ToString());
            }

            // Add necessary XmlInludes for abstract derived types used in the class
            if (xmlIncludedClasses.Count > 0)
            {
                outStream.WriteLine(", _");
            }
            for (int i = 0; i < xmlIncludedClasses.Count; i++)
            {
                outStream.Write("\tXmlInclude(GetType({0}))", CheckForKeywords((string)xmlIncludedClasses[i]));
                if ((i + 1) < xmlIncludedClasses.Count)
                {
                    outStream.WriteLine(", _");
                }
            }

            outStream.WriteLine("> _");

            string className = CheckForKeywords(dotnetClassName);

            outStream.WriteLine("\t{2}Public {1}Class {0}", className, isAbstract ? "MustInherit " : "", partialClasses ? PartialKeyword : "");

            // setup inheritance for <xsd:extension base="class">
            if (complexTypeBaseClass != null && complexTypeBaseClass != "")
            {
                outStream.WriteLine("\t\tInherits {0}", CheckForKeywords(complexTypeBaseClass));
            }

            // setup enumerability over a contained collection
            if (enumerableClasses.ContainsKey(dotnetClassName))
            {
                ArrayList values = (ArrayList)enumerableClasses[dotnetClassName];

                outStream.WriteLine();
                string collectionName = (string)values[0];
                collectionName = ReplaceInvalidChars(collectionName);
                outStream.WriteLine(ClassEnumerabilityTemplate, collectionName,
                                    ConvertSystemDatatype((string)values[1]), collectionSuffix, hiddenMemberPrefix);
            }
        }
 void ExportAttribute(CodeAttributeDeclarationCollection metadata, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, XmlSchemaForm form) {
     ExportMetadata(metadata, typeof(XmlAttributeAttribute), name, ns, typeDesc, dataTypeDesc, null, form, 0, -1);
 }
Ejemplo n.º 29
0
        void ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, string ns, XmlSchemaForm form, Type choiceIdentifierType) {
            int previousNestingLevel = arrayNestingLevel;
            XmlArrayItemAttributes previousArrayItemAttributes = savedArrayItemAttributes;
            string previousArrayNamespace = savedArrayNamespace;
            arrayNestingLevel = 0;
            savedArrayItemAttributes = null;
            savedArrayNamespace = null;
            Type accessorType = model.FieldType;
            string accessorName = model.Name;
            NameTable elements = new NameTable();
            accessor.TypeDesc = typeScope.GetTypeDesc(accessorType);
            XmlAttributeFlags flags = a.XmlFlags;
            accessor.Ignore = a.XmlIgnore;
            CheckAmbiguousChoice(a, accessorType, accessorName);

            XmlAttributeFlags elemFlags = XmlAttributeFlags.Elements | XmlAttributeFlags.Text | XmlAttributeFlags.AnyElements | XmlAttributeFlags.ChoiceIdentifier;
            XmlAttributeFlags attrFlags = XmlAttributeFlags.Attribute | XmlAttributeFlags.AnyAttribute;
            XmlAttributeFlags arrayFlags = XmlAttributeFlags.Array | XmlAttributeFlags.ArrayItems;

            // special case for byte[]. It can be a primitive (base64Binary or hexBinary), or it can
            // be an array of bytes. Our default is primitive; specify [XmlArray] to get array behavior.
            if ((flags & arrayFlags) != 0 && accessorType == typeof(byte[]))
                accessor.TypeDesc = typeScope.GetArrayTypeDesc(accessorType);


            if (a.XmlChoiceIdentifier != null) {
                accessor.ChoiceIdentifier = new ChoiceIdentifierAccessor();
                accessor.ChoiceIdentifier.MemberName = a.XmlChoiceIdentifier.MemberName;
                accessor.ChoiceIdentifier.Mapping = ImportTypeMapping(modelScope.GetTypeModel(choiceIdentifierType), ns, ImportContext.Element, String.Empty);
            }

            if (accessor.TypeDesc.IsArrayLike) {
                Type arrayElementType = TypeScope.GetArrayElementType(accessorType);

                if ((flags & attrFlags) != 0) {
                    if ((flags & attrFlags) != flags) 
                        throw new InvalidOperationException(Res.GetString(Res.XmlIllegalAttributesArrayAttribute));

                    if (a.XmlAttribute != null && !accessor.TypeDesc.ArrayElementTypeDesc.IsPrimitive && !accessor.TypeDesc.ArrayElementTypeDesc.IsEnum)
                        throw new InvalidOperationException(Res.GetString(Res.XmlIllegalAttrOrText, accessorName));

                    bool isList = a.XmlAttribute != null && (accessor.TypeDesc.ArrayElementTypeDesc.IsPrimitive || accessor.TypeDesc.ArrayElementTypeDesc.IsEnum);

                    if (a.XmlAnyAttribute != null) {
                        a.XmlAttribute = new XmlAttributeAttribute();
                    }

                    AttributeAccessor attribute = new AttributeAccessor();
                    Type targetType = a.XmlAttribute.Type == null ? arrayElementType : a.XmlAttribute.Type;
                    TypeDesc targetTypeDesc = typeScope.GetTypeDesc(targetType);
                    attribute.Name = Accessor.EscapeName(a.XmlAttribute.AttributeName.Length == 0 ? accessorName : a.XmlAttribute.AttributeName, true);
                    attribute.Namespace = a.XmlAttribute.Namespace == null ? ns : a.XmlAttribute.Namespace;
                    attribute.Form = a.XmlAttribute.Form;   // == XmlSchemaForm.None ? form : a.XmlAttribute.Form;
                    if (attribute.Form == XmlSchemaForm.None && ns != attribute.Namespace) {
                        attribute.Form = XmlSchemaForm.Qualified;
                    }
                    attribute.CheckSpecial();
                    CheckForm(attribute.Form, ns != attribute.Namespace);
                    attribute.Mapping = ImportTypeMapping(modelScope.GetTypeModel(targetType), ns, ImportContext.Attribute, a.XmlAttribute.DataType, XmlSchemaForm.Qualified, isList);
                    attribute.IsList = isList;
                    attribute.Default = GetDefaultValue(model.FieldTypeDesc, model.FieldType, a);
                    attribute.Any = (a.XmlAnyAttribute != null);
                    accessor.Attribute = attribute;

                }
                else if ((flags & elemFlags) != 0) {
                    if ((flags & elemFlags) != flags)
                        throw new InvalidOperationException(Res.GetString(Res.XmlIllegalElementsArrayAttribute));
                    
                    if (a.XmlText != null) {
                        TextAccessor text = new TextAccessor();
                        Type targetType = a.XmlText.Type == null ? arrayElementType : a.XmlText.Type;
                        TypeDesc targetTypeDesc = typeScope.GetTypeDesc(targetType);
                        text.Name = accessorName; // unused except to make more helpful error messages
                        text.Mapping = ImportTypeMapping(modelScope.GetTypeModel(targetType), ns, ImportContext.Text, a.XmlText.DataType, XmlSchemaForm.Qualified, true);
                        if (!(text.Mapping is SpecialMapping) && targetTypeDesc != typeScope.GetTypeDesc(typeof(string)))
                            throw new InvalidOperationException(Res.GetString(Res.XmlIllegalArrayTextAttribute, accessorName));

                        accessor.Text = text;
                    }
                    if (a.XmlText == null && a.XmlElements.Count == 0 && a.XmlAnyElements.Count == 0)
                        a.XmlElements.Add(CreateElementAttribute(accessor.TypeDesc));
                    
                    for (int i = 0; i < a.XmlElements.Count; i++) {
                        XmlElementAttribute xmlElement = a.XmlElements[i];
                        Type targetType = xmlElement.Type == null ? arrayElementType : xmlElement.Type;
                        TypeDesc targetTypeDesc = typeScope.GetTypeDesc(targetType);
                        TypeModel typeModel = modelScope.GetTypeModel(targetType);
                        ElementAccessor element = new ElementAccessor();
                        element.Namespace = xmlElement.Namespace == null ? ns : xmlElement.Namespace;
                        element.Mapping = ImportTypeMapping(typeModel, element.Namespace, ImportContext.Element, xmlElement.DataType);
                        if (a.XmlElements.Count == 1) {
	                        element.Name = Accessor.EscapeName(xmlElement.ElementName.Length == 0 ? accessorName : xmlElement.ElementName, false);
                        }
                        else {
	                        element.Name = Accessor.EscapeName(xmlElement.ElementName.Length == 0 ? element.Mapping.TypeName : xmlElement.ElementName, false);
                        }
                        element.Default = GetDefaultValue(model.FieldTypeDesc, model.FieldType, a);
                        element.IsNullable = xmlElement.IsNullable;
                        element.Form = xmlElement.Form == XmlSchemaForm.None ? form : xmlElement.Form;
                        CheckForm(element.Form, ns != element.Namespace);
                        CheckNullable(element.IsNullable, targetTypeDesc);
                        element = ReconcileLocalAccessor(element, ns);
                        AddUniqueAccessor(elements, element);
                    }
                    
                    for (int i = 0; i < a.XmlAnyElements.Count; i++) {
                        XmlAnyElementAttribute xmlAnyElement = a.XmlAnyElements[i];
                        Type targetType = typeof(XmlNode).IsAssignableFrom(arrayElementType) ? arrayElementType : typeof(XmlElement);
                        ElementAccessor element = new ElementAccessor();
                        element.Name = Accessor.EscapeName(xmlAnyElement.Name, false);
                        element.Namespace = xmlAnyElement.Namespace == null ? ns : xmlAnyElement.Namespace;
                        element.Any = true;
                        TypeDesc targetTypeDesc = typeScope.GetTypeDesc(targetType);
                        TypeModel typeModel = modelScope.GetTypeModel(targetType);
                        if (element.Name != String.Empty)
                            typeModel.TypeDesc.IsMixed = true;
                        else if (xmlAnyElement.Namespace != null)
                            throw new InvalidOperationException(Res.GetString(Res.XmlAnyElementNamespace, accessorName, xmlAnyElement.Namespace));
                        element.Mapping = ImportTypeMapping(typeModel, element.Namespace, ImportContext.Element, String.Empty);
                        element.Default = GetDefaultValue(model.FieldTypeDesc, model.FieldType, a);
                        element.IsNullable = false;
                        element.Form = form;
                        CheckForm(element.Form, ns != element.Namespace);
                        CheckNullable(element.IsNullable, targetTypeDesc);
                        element = ReconcileLocalAccessor(element, ns);
                        elements.Add(element.Name, element.Namespace, element);
                    }

                }
                else {
                    if ((flags & arrayFlags) != 0) {
                        if ((flags & arrayFlags) != flags)
                            throw new InvalidOperationException(Res.GetString(Res.XmlIllegalArrayArrayAttribute));
                    }
                    
                    TypeDesc arrayElementTypeDesc = typeScope.GetTypeDesc(arrayElementType);
                    if (a.XmlArray == null)
                        a.XmlArray = CreateArrayAttribute(accessor.TypeDesc);
                    if (CountAtLevel(a.XmlArrayItems, arrayNestingLevel) == 0)
                        a.XmlArrayItems.Add(CreateArrayItemAttribute(arrayElementTypeDesc, arrayNestingLevel));
                    ElementAccessor arrayElement = new ElementAccessor();
                    arrayElement.Name = Accessor.EscapeName(a.XmlArray.ElementName.Length == 0 ? accessorName : a.XmlArray.ElementName, false);
                    arrayElement.Namespace = a.XmlArray.Namespace == null ? ns : a.XmlArray.Namespace;
                    savedArrayItemAttributes = a.XmlArrayItems;
                    savedArrayNamespace = arrayElement.Namespace;
                    ArrayMapping arrayMapping = ImportArrayLikeMapping(modelScope.GetArrayModel(accessorType), ns, form);
                    arrayElement.Mapping = arrayMapping;
                    arrayElement.IsNullable = a.XmlArray.IsNullable;
                    arrayElement.Form = a.XmlArray.Form == XmlSchemaForm.None ? form : a.XmlArray.Form;
                    CheckForm(arrayElement.Form, ns != arrayElement.Namespace);
                    CheckNullable(arrayElement.IsNullable, accessor.TypeDesc);
                    savedArrayItemAttributes = null;
                    savedArrayNamespace = null;
                    arrayElement = ReconcileLocalAccessor(arrayElement, ns);
                    AddUniqueAccessor(elements, arrayElement);
                }
            }
            else if (!accessor.TypeDesc.IsVoid) {
                XmlAttributeFlags allFlags = XmlAttributeFlags.Elements | XmlAttributeFlags.Text | XmlAttributeFlags.Attribute | XmlAttributeFlags.AnyElements | XmlAttributeFlags.ChoiceIdentifier | XmlAttributeFlags.XmlnsDeclarations;
                if ((flags & allFlags) != flags)
                    throw new InvalidOperationException(Res.GetString(Res.XmlIllegalAttribute));

                if (accessor.TypeDesc.IsPrimitive || accessor.TypeDesc.IsEnum) {
                    if (a.XmlAnyElements.Count > 0) throw new InvalidOperationException(Res.GetString(Res.XmlIllegalAnyElement));

                    if (a.XmlAttribute != null) {
                        if (a.XmlElements.Count > 0) throw new InvalidOperationException(Res.GetString(Res.XmlIllegalAttribute));
                        if (a.XmlAttribute.Type != null) throw new InvalidOperationException(Res.GetString(Res.XmlIllegalType, "XmlAttribute"));
                        AttributeAccessor attribute = new AttributeAccessor();
                        attribute.Name = Accessor.EscapeName(a.XmlAttribute.AttributeName.Length == 0 ? accessorName : a.XmlAttribute.AttributeName, true);
                        attribute.Namespace = a.XmlAttribute.Namespace == null ? ns : a.XmlAttribute.Namespace;
                        attribute.Form = a.XmlAttribute.Form;   // == XmlSchemaForm.None ? form : a.XmlAttribute.Form;
                        if (attribute.Form == XmlSchemaForm.None && ns != attribute.Namespace) {
                            attribute.Form = XmlSchemaForm.Qualified;
                        }
                        attribute.CheckSpecial();
                        CheckForm(attribute.Form, ns != attribute.Namespace);
                        attribute.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), ns, ImportContext.Attribute, a.XmlAttribute.DataType);
                        attribute.Default = GetDefaultValue(model.FieldTypeDesc, model.FieldType, a);
                        attribute.Any = a.XmlAnyAttribute != null;
                        accessor.Attribute = attribute;
                    }
                    else {
                        if (a.XmlText != null) {
                            if (a.XmlText.Type != null && a.XmlText.Type != accessorType) 
                                throw new InvalidOperationException(Res.GetString(Res.XmlIllegalType, "XmlText"));
                            TextAccessor text = new TextAccessor();
                            text.Name = accessorName; // unused except to make more helpful error messages
                            text.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), ns, ImportContext.Text, a.XmlText.DataType);
                            accessor.Text = text;
                        }
                        else if (a.XmlElements.Count == 0) {
                            a.XmlElements.Add(CreateElementAttribute(accessor.TypeDesc));
                        }

                        for (int i = 0; i < a.XmlElements.Count; i++) {
                            XmlElementAttribute xmlElement = a.XmlElements[i];
                            if (xmlElement.Type != null) {
                                if (typeScope.GetTypeDesc(xmlElement.Type) != accessor.TypeDesc)
                                    throw new InvalidOperationException(Res.GetString(Res.XmlIllegalType, "XmlElement"));
                            }
                            ElementAccessor element = new ElementAccessor();
                            element.Name = Accessor.EscapeName(xmlElement.ElementName.Length == 0 ? accessorName : xmlElement.ElementName, false);
                            element.Namespace = xmlElement.Namespace == null ? ns : xmlElement.Namespace;
                            element.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), element.Namespace, ImportContext.Element, xmlElement.DataType);
                            element.Default = GetDefaultValue(model.FieldTypeDesc, model.FieldType, a);
                            element.IsNullable = xmlElement.IsNullable;
                            element.Form = xmlElement.Form == XmlSchemaForm.None ? form : xmlElement.Form;
                            CheckForm(element.Form, ns != element.Namespace);
                            CheckNullable(element.IsNullable, accessor.TypeDesc);
                            element = ReconcileLocalAccessor(element, ns);
                            AddUniqueAccessor(elements, element);
                        }
                    }
                }
                else if (a.Xmlns) {
                    if (flags != XmlAttributeFlags.XmlnsDeclarations)
                        throw new InvalidOperationException(Res.GetString(Res.XmlSoleXmlnsAttribute));
                    
                    if (accessorType != typeof(XmlSerializerNamespaces)) {
                        throw new InvalidOperationException(Res.GetString(Res.XmlXmlnsInvalidType, accessorName, accessorType.FullName, typeof(XmlSerializerNamespaces).FullName));
                    }
                    accessor.Xmlns = new XmlnsAccessor();
                    accessor.Ignore = true;
                }
                else  {
                    if (a.XmlAttribute != null || a.XmlText != null) throw new InvalidOperationException(Res.GetString(Res.XmlIllegalAttrOrText, accessorName));
                    if (a.XmlElements.Count == 0 && a.XmlAnyElements.Count == 0)
                        a.XmlElements.Add(CreateElementAttribute(accessor.TypeDesc));
                    for (int i = 0; i < a.XmlElements.Count; i++) {
                        XmlElementAttribute xmlElement = a.XmlElements[i];
                        Type targetType = xmlElement.Type == null ? accessorType : xmlElement.Type;
                        TypeDesc targetTypeDesc = typeScope.GetTypeDesc(targetType);
                        ElementAccessor element = new ElementAccessor();
                        TypeModel typeModel = modelScope.GetTypeModel(targetType);
                        element.Namespace = xmlElement.Namespace == null ? ns : xmlElement.Namespace;
                        element.Mapping = ImportTypeMapping(typeModel, element.Namespace, ImportContext.Element, xmlElement.DataType);
                        if (a.XmlElements.Count == 1) {
                            element.Name = Accessor.EscapeName(xmlElement.ElementName.Length == 0 ? accessorName : xmlElement.ElementName, false);
                        }
                        else {
                            element.Name = Accessor.EscapeName(xmlElement.ElementName.Length == 0 ? element.Mapping.TypeName : xmlElement.ElementName, false);
                        }
                        element.Default = GetDefaultValue(model.FieldTypeDesc, model.FieldType, a);
                        element.IsNullable = xmlElement.IsNullable;
                        element.Form = xmlElement.Form == XmlSchemaForm.None ? form : xmlElement.Form;
                        CheckForm(element.Form, ns != element.Namespace);
                        CheckNullable(element.IsNullable, targetTypeDesc);
                        element = ReconcileLocalAccessor(element, ns);
                        AddUniqueAccessor(elements, element);
                    }
                    
                    for (int i = 0; i < a.XmlAnyElements.Count; i++) {
                        XmlAnyElementAttribute xmlAnyElement = a.XmlAnyElements[i];
                        Type targetType = typeof(XmlNode).IsAssignableFrom(accessorType) ? accessorType : typeof(XmlElement);
                        ElementAccessor element = new ElementAccessor();
                        element.Name = Accessor.EscapeName(xmlAnyElement.Name, false);
                        element.Namespace = xmlAnyElement.Namespace == null ? ns : xmlAnyElement.Namespace;
                        element.Any = true;
                        TypeDesc targetTypeDesc = typeScope.GetTypeDesc(targetType);
                        TypeModel typeModel = modelScope.GetTypeModel(targetType);
                        if (element.Name != String.Empty)
                            typeModel.TypeDesc.IsMixed = true;
                        else if (xmlAnyElement.Namespace != null)
                            throw new InvalidOperationException(Res.GetString(Res.XmlAnyElementNamespace, accessorName, xmlAnyElement.Namespace));
                        element.Mapping = ImportTypeMapping(typeModel, element.Namespace, ImportContext.Element, String.Empty);
                        element.Default = GetDefaultValue(model.FieldTypeDesc, model.FieldType, a);
                        element.IsNullable = false;
                        element.Form = form;
                        CheckForm(element.Form, ns != element.Namespace);
                        CheckNullable(element.IsNullable, targetTypeDesc);
                        element = ReconcileLocalAccessor(element, ns);
                        elements.Add(element.Name, element.Namespace, element);
                    }
                }
            }

            accessor.Elements = (ElementAccessor[])elements.ToArray(typeof(ElementAccessor));

            if (accessor.ChoiceIdentifier != null) {
                // find the enum value corresponding to each element
                accessor.ChoiceIdentifier.MemberIds = new string[accessor.Elements.Length];
                for (int i = 0; i < accessor.Elements.Length; i++) {
                    bool found = false;
                    ElementAccessor element = accessor.Elements[i];
                    EnumMapping choiceMapping = (EnumMapping)accessor.ChoiceIdentifier.Mapping;
                    for (int j = 0; j < choiceMapping.Constants.Length; j++) {
                        string xmlName = choiceMapping.Constants[j].XmlName;
                        int colon = xmlName.LastIndexOf(':');
                        string choiceNs = colon < 0 ? element.Namespace : xmlName.Substring(0, colon);
                        string choiceName = colon < 0 ? xmlName : xmlName.Substring(colon+1);
                        if (element.Name == choiceName && element.Namespace == choiceNs) {
                            accessor.ChoiceIdentifier.MemberIds[i] = choiceMapping.Constants[j].Name;
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        // Type {0} is missing value for '{1}'.
                        throw new InvalidOperationException(Res.GetString(Res.XmlChoiceMissingValue, accessor.ChoiceIdentifier.Mapping.TypeDesc.FullName, element.Name));
                    }
                }
            }
            arrayNestingLevel = previousNestingLevel;
            savedArrayItemAttributes = previousArrayItemAttributes;
            savedArrayNamespace = previousArrayNamespace;
        }
Ejemplo n.º 30
0
        private MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlReflectionMember[] xmlReflectionMembers, XmlSchemaForm form, RecursionLimiter limiter)
        {
            SoapAttributes soapAttributes = xmlReflectionMember.SoapAttributes;

            if (soapAttributes.SoapIgnore)
            {
                return(null);
            }
            MemberMapping accessor = new MemberMapping {
                IsSoap = true,
                Name   = xmlReflectionMember.MemberName
            };
            bool       checkSpecified = XmlReflectionImporter.FindSpecifiedMember(xmlReflectionMember.MemberName, xmlReflectionMembers) != null;
            FieldModel model          = new FieldModel(xmlReflectionMember.MemberName, xmlReflectionMember.MemberType, this.typeScope.GetTypeDesc(xmlReflectionMember.MemberType), checkSpecified, false);

            accessor.CheckShouldPersist = model.CheckShouldPersist;
            accessor.CheckSpecified     = model.CheckSpecified;
            accessor.ReadOnly           = model.ReadOnly;
            this.ImportAccessorMapping(accessor, model, soapAttributes, ns, form, limiter);
            if (xmlReflectionMember.OverrideIsNullable)
            {
                accessor.Elements[0].IsNullable = false;
            }
            return(accessor);
        }
Ejemplo n.º 31
0
        private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, SoapAttributes a, string ns, XmlSchemaForm form, RecursionLimiter limiter)
        {
            Type   fieldType = model.FieldType;
            string name      = model.Name;

            accessor.TypeDesc = this.typeScope.GetTypeDesc(fieldType);
            if (accessor.TypeDesc.IsVoid)
            {
                throw new InvalidOperationException(Res.GetString("XmlInvalidVoid"));
            }
            SoapAttributeFlags soapFlags = a.SoapFlags;

            if ((soapFlags & SoapAttributeFlags.Attribute) == SoapAttributeFlags.Attribute)
            {
                if (!accessor.TypeDesc.IsPrimitive && !accessor.TypeDesc.IsEnum)
                {
                    throw new InvalidOperationException(Res.GetString("XmlIllegalSoapAttribute", new object[] { name, accessor.TypeDesc.FullName }));
                }
                if ((soapFlags & SoapAttributeFlags.Attribute) != soapFlags)
                {
                    throw new InvalidOperationException(Res.GetString("XmlInvalidElementAttribute"));
                }
                AttributeAccessor accessor2 = new AttributeAccessor {
                    Name      = Accessor.EscapeQName(((a.SoapAttribute == null) || (a.SoapAttribute.AttributeName.Length == 0)) ? name : a.SoapAttribute.AttributeName),
                    Namespace = ((a.SoapAttribute == null) || (a.SoapAttribute.Namespace == null)) ? ns : a.SoapAttribute.Namespace,
                    Form      = XmlSchemaForm.Qualified,
                    Mapping   = this.ImportTypeMapping(this.modelScope.GetTypeModel(fieldType), (a.SoapAttribute == null) ? string.Empty : a.SoapAttribute.DataType, limiter),
                    Default   = this.GetDefaultValue(model.FieldTypeDesc, a)
                };
                accessor.Attribute = accessor2;
                accessor.Elements  = new ElementAccessor[0];
            }
            else
            {
                if ((soapFlags & SoapAttributeFlags.Element) != soapFlags)
                {
                    throw new InvalidOperationException(Res.GetString("XmlInvalidElementAttribute"));
                }
                ElementAccessor accessor3 = new ElementAccessor {
                    IsSoap    = true,
                    Name      = XmlConvert.EncodeLocalName(((a.SoapElement == null) || (a.SoapElement.ElementName.Length == 0)) ? name : a.SoapElement.ElementName),
                    Namespace = ns,
                    Form      = form,
                    Mapping   = this.ImportTypeMapping(this.modelScope.GetTypeModel(fieldType), (a.SoapElement == null) ? string.Empty : a.SoapElement.DataType, limiter)
                };
                if (a.SoapElement != null)
                {
                    accessor3.IsNullable = a.SoapElement.IsNullable;
                }
                accessor.Elements = new ElementAccessor[] { accessor3 };
            }
        }
Ejemplo n.º 32
0
		XmlTypeMapElementInfo CreateElementInfo (string ns, XmlTypeMapMember member, string name, TypeData typeData, bool isNillable, XmlSchemaForm form, int order)
		{
			if (typeData.IsComplexType)
				return CreateElementInfo (ns, member, name, typeData, isNillable, form, GetTypeMapping (typeData), order);
			else
				return CreateElementInfo (ns, member, name, typeData, isNillable, form, null, order);
		}
Ejemplo n.º 33
0
		XmlTypeMapElementInfo CreateElementInfo (string ns, XmlTypeMapMember member, string name, TypeData typeData, bool isNillable, XmlSchemaForm form, XmlTypeMapping emap)
		{
			XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, typeData);
			einfo.ElementName = name;
			einfo.Namespace = ns;
			einfo.IsNullable = isNillable;
			einfo.Form = form;
			if (typeData.IsComplexType)
				einfo.MappedType = emap;
			return einfo;
		}
Ejemplo n.º 34
0
		XmlSchemaForm GetForm (XmlSchemaForm form, string ns, bool forElement)
		{
			// Returns the schema form for an element or attribute, taking
			// into account the schema defaults. If the form has not been explicitly
			// set and there is no default, use Unqualified as default.
			
			if (form != XmlSchemaForm.None)
				return form;
			XmlSchema s = schemas [ns];
			if (s == null)
				return XmlSchemaForm.Unqualified;
			XmlSchemaForm schemaForm = forElement ? s.ElementFormDefault : s.AttributeFormDefault;
			if (schemaForm != XmlSchemaForm.None)
				return schemaForm;
			else
				return XmlSchemaForm.Unqualified;
		}
        MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlSchemaForm form)
        {
            SoapAttributes a = xmlReflectionMember.SoapAttributes;

            if (a.SoapIgnore)
            {
                return(null);
            }
            MemberMapping member = new MemberMapping();

            member.IsSoap = true;
            member.Name   = xmlReflectionMember.MemberName;
            FieldModel model = new FieldModel(xmlReflectionMember.MemberName, xmlReflectionMember.MemberType, typeScope.GetTypeDesc(xmlReflectionMember.MemberType), false, false);

            member.ReadOnly = model.ReadOnly || !model.FieldTypeDesc.HasDefaultConstructor;
            ImportAccessorMapping(member, model, a, ns, form);
            if (xmlReflectionMember.OverrideIsNullable)
            {
                member.Elements[0].IsNullable = false;
            }
            return(member);
        }
Ejemplo n.º 36
0
        private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, SoapAttributes a, string ns, XmlSchemaForm form, RecursionLimiter limiter)
        {
            Type   accessorType = model.FieldType;
            string accessorName = model.Name;

            accessor.TypeDesc = _typeScope.GetTypeDesc(accessorType);
            if (accessor.TypeDesc.IsVoid)
            {
                throw new InvalidOperationException(SR.XmlInvalidVoid);
            }

            SoapAttributeFlags flags = a.GetSoapFlags();

            if ((flags & SoapAttributeFlags.Attribute) == SoapAttributeFlags.Attribute)
            {
                if (!accessor.TypeDesc.IsPrimitive && !accessor.TypeDesc.IsEnum)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlIllegalSoapAttribute, accessorName, accessor.TypeDesc.FullName));
                }

                if ((flags & SoapAttributeFlags.Attribute) != flags)
                {
                    throw new InvalidOperationException(SR.XmlInvalidElementAttribute);
                }

                AttributeAccessor attribute = new AttributeAccessor();
                attribute.Name      = Accessor.EscapeQName(a.SoapAttribute == null || a.SoapAttribute.AttributeName.Length == 0 ? accessorName : a.SoapAttribute.AttributeName);
                attribute.Namespace = a.SoapAttribute == null || a.SoapAttribute.Namespace == null ? ns : a.SoapAttribute.Namespace;
                attribute.Form      = XmlSchemaForm.Qualified; // attributes are always qualified since they're only used for encoded soap headers
                attribute.Mapping   = ImportTypeMapping(_modelScope.GetTypeModel(accessorType), (a.SoapAttribute == null ? String.Empty : a.SoapAttribute.DataType), limiter);
                attribute.Default   = GetDefaultValue(model.FieldTypeDesc, a);
                accessor.Attribute  = attribute;
                accessor.Elements   = Array.Empty <ElementAccessor>();
            }
            else
            {
                if ((flags & SoapAttributeFlags.Element) != flags)
                {
                    throw new InvalidOperationException(SR.XmlInvalidElementAttribute);
                }

                ElementAccessor element = new ElementAccessor();
                element.IsSoap    = true;
                element.Name      = XmlConvert.EncodeLocalName(a.SoapElement == null || a.SoapElement.ElementName.Length == 0 ? accessorName : a.SoapElement.ElementName);
                element.Namespace = ns;
                element.Form      = form;
                element.Mapping   = ImportTypeMapping(_modelScope.GetTypeModel(accessorType), (a.SoapElement == null ? String.Empty : a.SoapElement.DataType), limiter);
                if (a.SoapElement != null)
                {
                    element.IsNullable = a.SoapElement.IsNullable;
                }
                accessor.Elements = new ElementAccessor[] { element };
            }
        }
 void ExportArrayItem(CodeAttributeDeclarationCollection metadata, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, bool isNullable, XmlSchemaForm form, int nestingLevel) {
     ExportMetadata(metadata, typeof(XmlArrayItemAttribute), name, ns, typeDesc, dataTypeDesc, isNullable ? null : (object)false, form, nestingLevel, -1);
 }
Ejemplo n.º 38
0
        internal void ProcessDecorations()
        {
            if (XmlAttribute != null)
            {
                if (!string.IsNullOrEmpty(XmlAttribute.AttributeName))
                {
                    _nodeName = XmlAttribute.AttributeName;
                }
                _namespace = XmlAttribute.Namespace;
                Form       = XmlAttribute.Form;
                _nodeType  = XPathNodeType.Attribute;
            }

            else if (XmlElement != null)
            {
                if (!string.IsNullOrEmpty(XmlElement.ElementName))
                {
                    _nodeName = XmlElement.ElementName;
                }
                _namespace = XmlElement.Namespace;
                Form       = XmlElement.Form;
                _nodeType  = XPathNodeType.Element;
                if (typeof(IList).IsAssignableFrom(Type))
                {
                    _isTransparent = true;
                }
            }

            else if (XmlAnyElement != null)
            {
                if (!string.IsNullOrEmpty(XmlAnyElement.Name))
                {
                    _nodeName = XmlAnyElement.Name;
                }
                _namespace = XmlAnyElement.Namespace;
                Form       = XmlSchemaForm.Qualified;

/*
 *                              if( _namespace != null )
 *                                      Form = XmlSchemaForm.Qualified;
 *                              else
 *                                      Form = XmlSchemaForm.Unqualified;
 */
                _nodeType      = XPathNodeType.Element;
                _isTransparent = true;

                if (typeof(XmlNode[]).IsAssignableFrom(Type))
                {
                    Add(new NodePolicyAttribute(typeof(AnyElementXmlNodeArrayNodePolicy)));
                }
            }

            else if (XmlText != null)
            {
                _nodeType = XPathNodeType.Text;
            }

            if (Converter != null)
            {
                base.ConverterType = Converter.ConverterType;
            }

            if (Transparent != null)
            {
                _isTransparent = Transparent.IsTransparent;
            }
        }
Ejemplo n.º 39
0
 public override void ClassHeaderCode(StreamWriter outStream, string dotnetClassName, string elementName, string complexTypeBaseClass, bool baseIsAbstract, bool isSchemaType, bool isAbstract, bool isLocalComplexType, Hashtable enumerableClasses, string ns, XmlSchemaForm elementFormDefault, string annotation, bool isElementNullable, ArrayList xmlIncludedClasses, bool globalElementAndSchemaTypeHaveSameName)
 {
     outStream.WriteLine();
     outStream.WriteLine();
     string str = "";
     if (isSchemaType)
     {
         if ((elementFormDefault == XmlSchemaForm.Qualified) || (elementFormDefault == XmlSchemaForm.Unqualified))
         {
             str = this.CalculateNamespace(base.schemaTargetNamespace, ns, false);
         }
         if (globalElementAndSchemaTypeHaveSameName)
         {
             outStream.WriteLine("\t[XmlRoot(ElementName=\"{0}\"{1},IsNullable={2}),Serializable]", elementName, str, isElementNullable.ToString().ToLower());
             outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1})]", dotnetClassName, str);
         }
         else
         {
             outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1}),Serializable]\r\n\t[EditorBrowsable(EditorBrowsableState.{2})]", dotnetClassName, str, baseIsAbstract ? "Always" : "Advanced");
         }
     }
     else if (isLocalComplexType)
     {
         if ((elementFormDefault == XmlSchemaForm.Qualified) || (elementFormDefault == XmlSchemaForm.Unqualified))
         {
             str = this.CalculateNamespace(base.schemaTargetNamespace, ns, false);
         }
         outStream.WriteLine("\t[XmlType(TypeName=\"{0}\"{1}),Serializable]", dotnetClassName, str);
     }
     else
     {
         str = this.CalculateNamespace(base.schemaTargetNamespace, ns, false);
         outStream.WriteLine("\t[XmlRoot(ElementName=\"{0}\"{1},IsNullable={2}),Serializable]", elementName, str, isElementNullable.ToString().ToLower());
     }
     foreach (string str2 in xmlIncludedClasses)
     {
         outStream.WriteLine("\t[XmlInclude(typeof({0}))]", this.CheckForKeywords(str2));
     }
     string str3 = this.CheckForKeywords(dotnetClassName);
     outStream.Write("\tpublic {1}{2}class {0}", str3, isAbstract ? "abstract " : "", LanguageBase.partialClasses ? this.PartialKeyword : "");
     if ((complexTypeBaseClass != null) && (complexTypeBaseClass != ""))
     {
         outStream.Write(" : {0}", this.CheckForKeywords(complexTypeBaseClass));
     }
     outStream.WriteLine();
     outStream.WriteLine("\t{");
     if (enumerableClasses.ContainsKey(dotnetClassName))
     {
         ArrayList list = (ArrayList) enumerableClasses[dotnetClassName];
         string invalid = (string) list[0];
         invalid = LanguageBase.ReplaceInvalidChars(invalid);
         outStream.WriteLine(this.ClassEnumerabilityTemplate, new object[] { invalid, this.ConvertSystemDatatype((string) list[1]), LanguageBase.collectionSuffix, LanguageBase.hiddenMemberPrefix });
     }
 }
 void ExportElement(CodeAttributeDeclarationCollection metadata, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, bool isNullable, XmlSchemaForm form, int sequenceId) {
     ExportMetadata(metadata, typeof(XmlElementAttribute), name, ns, typeDesc, dataTypeDesc, isNullable ? (object)true : null, form, 0, sequenceId);
 }
Ejemplo n.º 41
0
		XmlTypeMapElementInfo CreateElementInfo (string ns, XmlTypeMapMember member, string name, TypeData typeData, bool isNillable, XmlSchemaForm form, XmlTypeMapping emap, int order)
		{
			XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, typeData);
			einfo.ElementName = name;
			einfo.Namespace = ns;
			einfo.IsNullable = isNillable;
			einfo.Form = GetForm (form, ns, true);
			if (typeData.IsComplexType)
				einfo.MappedType = emap;
			einfo.ExplicitOrder = order;
			return einfo;
		}
 void ExportArray(CodeAttributeDeclarationCollection metadata, string name, string ns, bool isNullable, XmlSchemaForm form, int sequenceId) {
     ExportMetadata(metadata, typeof(XmlArrayAttribute), name, ns, null, null, isNullable ? (object)true : null, form, 0, sequenceId);
 }
Ejemplo n.º 43
0
        private MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlReflectionMember[] xmlReflectionMembers, XmlSchemaForm form, RecursionLimiter limiter)
        {
            SoapAttributes a = xmlReflectionMember.SoapAttributes;

            if (a.SoapIgnore)
            {
                return(null);
            }
            MemberMapping member = new MemberMapping();

            member.IsSoap = true;
            member.Name   = xmlReflectionMember.MemberName;
            bool       checkSpecified = XmlReflectionImporter.FindSpecifiedMember(xmlReflectionMember.MemberName, xmlReflectionMembers) != null;
            FieldModel model          = new FieldModel(xmlReflectionMember.MemberName, xmlReflectionMember.MemberType, _typeScope.GetTypeDesc(xmlReflectionMember.MemberType), checkSpecified, false);

            member.CheckShouldPersist = model.CheckShouldPersist;
            member.CheckSpecified     = model.CheckSpecified;
            member.ReadOnly           = model.ReadOnly; // || !model.FieldTypeDesc.HasDefaultConstructor;
            ImportAccessorMapping(member, model, a, ns, form, limiter);
            if (xmlReflectionMember.OverrideIsNullable)
            {
                member.Elements[0].IsNullable = false;
            }
            return(member);
        }
        void ExportMetadata(CodeAttributeDeclarationCollection metadata, Type attributeType, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, object isNullable, XmlSchemaForm form, int nestingLevel, int sequenceId) {
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType.FullName);
            if (name != null) {
                attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(name)));
            }
            if (typeDesc != null) {
                if (isNullable != null && (bool)isNullable && typeDesc.IsValueType && !typeDesc.IsMappedType && CodeProvider.Supports(GeneratorSupport.GenericTypeReference)) {
                    attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression("System.Nullable`1[" + typeDesc.FullName + "]")));
                    isNullable = null;
                }
                else {
                    attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(typeDesc.FullName)));
                }
            }
            if (form != XmlSchemaForm.None) {
                attribute.Arguments.Add(new CodeAttributeArgument("Form", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(XmlSchemaForm).FullName), Enum.Format(typeof(XmlSchemaForm), form, "G"))));

                if (form == XmlSchemaForm.Unqualified && ns != null && ns.Length == 0) {
                    ns = null;
                }
            }
            if (ns != null ) {
                attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
            }
            if (dataTypeDesc != null && dataTypeDesc.IsAmbiguousDataType && !dataTypeDesc.IsMappedType) {
                attribute.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(dataTypeDesc.DataType.Name)));
            }
            if (isNullable != null) {
                attribute.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression((bool)isNullable)));
            }
            if (nestingLevel > 0) {
                attribute.Arguments.Add(new CodeAttributeArgument("NestingLevel", new CodePrimitiveExpression(nestingLevel)));
            }
            if (sequenceId >= 0) {
                attribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(sequenceId)));
            }
            if (attribute.Arguments.Count == 0 && attributeType == typeof(XmlElementAttribute)) return;
            metadata.Add(attribute);
        }
Ejemplo n.º 45
0
 /// <summary>
 /// Creates a new <see cref="MemberInfo"/> instance.
 /// </summary>
 protected MemberInfo( )
 {
     _nodeName = string.Empty;
     _nodeType = XPathNodeType.Element;
     Form      = XmlSchemaForm.None;
 }
Ejemplo n.º 46
0
        ElementAccessor ImportElement(TypeModel model, XmlRootAttribute root, string defaultNamespace, XmlSchemaForm form) {
            XmlAttributes a = GetAttributes(model.Type);

            if (root == null)
                root = a.XmlRoot;
            string ns = root == null ? null : root.Namespace;
            if (ns == null) ns = defaultNamespace;
            if (ns == null) ns = this.defaultNs;

            arrayNestingLevel = -1;
            savedArrayItemAttributes = null;
            savedArrayNamespace = null;
            ElementAccessor element = CreateElementAccessor(ImportTypeMapping(model, ns, ImportContext.Element, string.Empty, form, false), ns);

            if (root != null) {
                if (root.ElementName.Length > 0)
                    element.Name = Accessor.EscapeName(root.ElementName, false);
                element.IsNullable = root.IsNullableSpecified ? root.IsNullable : model.TypeDesc.IsNullable;
                CheckNullable(element.IsNullable, model.TypeDesc);
            }
            else
                element.IsNullable = model.TypeDesc.IsNullable;
            element.Form = form;
            return ReconcileAccessor(element);
        }
Ejemplo n.º 47
0
 void ExportArrayItem(CodeAttributeDeclarationCollection metadata, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, bool isNullable, XmlSchemaForm form, int nestingLevel)
 {
     ExportMetadata(metadata, typeof(XmlArrayItemAttribute), name, ns, typeDesc, dataTypeDesc, isNullable ? null : (object)false, form, nestingLevel);
 }
Ejemplo n.º 48
0
        TypeMapping ImportTypeMapping(TypeModel model, string ns, ImportContext context, string dataType, XmlSchemaForm form, bool repeats) {
            
            if (dataType.Length > 0) {
                if (!model.TypeDesc.IsPrimitive) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDataTypeUsage, dataType, "XmlElementAttribute.DataType"));
                }
                TypeDesc td = typeScope.GetTypeDesc(new XmlQualifiedName(dataType, XmlSchema.Namespace));
                if (td == null) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidXsdDataType, dataType, "XmlElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
                }
                if (model.TypeDesc.FullName != td.FullName) {
                    throw new InvalidOperationException(Res.GetString(Res.XmlDataTypeMismatch, dataType, "XmlElementAttribute.DataType", model.TypeDesc.FullName));
                }
            }

            XmlAttributes a = GetAttributes(model.Type);
            
            if ((a.XmlFlags & ~(XmlAttributeFlags.Type | XmlAttributeFlags.Root)) != 0)
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidTypeAttributes, model.Type.FullName));

            switch (model.TypeDesc.Kind) {
                case TypeKind.Enum: 
                    return ImportEnumMapping((EnumModel)model, ns, repeats);
                case TypeKind.Primitive:
                    if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    return ImportPrimitiveMapping((PrimitiveModel)model, context, dataType, repeats);
                case TypeKind.Array:
                case TypeKind.Collection:
                case TypeKind.Enumerable:
                    if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    if (context != ImportContext.Element) throw UnsupportedException(model.TypeDesc, context);
                    arrayNestingLevel++;
                    ArrayMapping arrayMapping = ImportArrayLikeMapping((ArrayModel)model, ns, form);
                    arrayNestingLevel--;
                    return arrayMapping;
                case TypeKind.Root:
                case TypeKind.Class:
                case TypeKind.Struct:
                case TypeKind.Interface:
                    if (context != ImportContext.Element) throw UnsupportedException(model.TypeDesc, context);
                    return ImportStructLikeMapping((StructModel)model, ns, form);
                default:
                    if (a.XmlFlags != 0) throw InvalidAttributeUseException(model.Type);
                    if (model.TypeDesc.IsSpecial)
                        return ImportSpecialMapping(model.Type, model.TypeDesc, ns, context);
                    throw UnsupportedException(model.TypeDesc, context);
            }
        }
Ejemplo n.º 49
0
 void ExportArray(CodeAttributeDeclarationCollection metadata, string name, string ns, bool isNullable, XmlSchemaForm form)
 {
     ExportMetadata(metadata, typeof(XmlArrayAttribute), name, ns, null, null, isNullable ? (object)true : null, form, 0);
 }
Ejemplo n.º 50
0
        StructMapping ImportStructLikeMapping(StructModel model, string ns, XmlSchemaForm form) {
            if (model.TypeDesc.Kind == TypeKind.Root) return GetRootMapping();
            XmlAttributes a = GetAttributes(model.Type);

            string typeNs = ns;
            if (a.XmlType != null && a.XmlType.Namespace != null)
                typeNs = a.XmlType.Namespace;
            else if (a.XmlRoot != null && a.XmlRoot.Namespace != null)
                typeNs = a.XmlRoot.Namespace;

            string typeName = string.Empty;
            if (a.XmlType != null)
                typeName = a.XmlType.TypeName;
            if (typeName.Length == 0) 
                typeName = model.TypeDesc.Name;

            StructMapping mapping = (StructMapping)GetTypeMapping(typeName, typeNs, model.TypeDesc);
            if (mapping == null) {
                mapping = new StructMapping();
                mapping.TypeDesc = model.TypeDesc;
                mapping.Namespace = typeNs;
                mapping.TypeName = typeName;
                typeScope.AddTypeMapping(mapping);
                types.Add(typeName, typeNs, mapping);
                if (a.XmlType != null) {
                    mapping.IncludeInSchema = a.XmlType.IncludeInSchema;
                }
                if (model.TypeDesc.BaseTypeDesc != null) {
                    mapping.BaseMapping = ImportStructLikeMapping((StructModel)modelScope.GetTypeModel(model.Type.BaseType), mapping.Namespace, form);
                    ICollection values = mapping.BaseMapping.LocalElements.Values;
                    foreach (ElementAccessor e in values) {
                        AddUniqueAccessor(mapping.LocalElements, e);
                    }
                    values = mapping.BaseMapping.LocalAttributes.Values;
                    foreach (AttributeAccessor attribute in values) {
                        AddUniqueAccessor(mapping.LocalAttributes, attribute);
                    }
                }
                ArrayList members = new ArrayList();
                TextAccessor textAccesor = null;
                bool hasElements = false;

                foreach (MemberInfo memberInfo in model.GetMemberInfos()) {
                    XmlAttributes memberAttrs = GetAttributes(memberInfo);
                    if (memberAttrs.XmlIgnore) continue;
                    FieldModel fieldModel = model.GetFieldModel(memberInfo);
                    if (fieldModel == null) continue;
                    MemberMapping member = ImportFieldMapping(model, fieldModel, memberAttrs, mapping.Namespace, form);
                    if (member == null) continue;
                    if (mapping.BaseMapping != null) {
                        if (mapping.BaseMapping.Declares(member, mapping.TypeName)) continue;
                    }
                    // add All memeber accessors to the scope accessors
                    AddUniqueAccessor(member, mapping.LocalElements, mapping.LocalAttributes);

                    if (member.Text != null) {
                        if (!member.Text.Mapping.TypeDesc.CanBeTextValue && member.Text.Mapping.IsList)
                            throw new InvalidOperationException(Res.GetString(Res.XmlIllegalTypedTextAttribute, typeName, member.Text.Name, member.Text.Mapping.TypeDesc.FullName));
                        if (textAccesor != null) {
                            throw new InvalidOperationException(Res.GetString(Res.XmlIllegalMultipleText, model.Type.FullName));
                        }
                        textAccesor = member.Text;
                    }
                    if (member.Xmlns != null) {
                        if (mapping.XmlnsMember != null)
                            throw new InvalidOperationException(Res.GetString(Res.XmlMultipleXmlns, model.Type.FullName));
                        mapping.XmlnsMember = member;
                    }
                    if (member.Elements != null && member.Elements.Length != 0) {
                        hasElements = true;
                    }
                    members.Add(member);
                }
                mapping.SetContentModel(textAccesor, hasElements);
                mapping.Members = (MemberMapping[])members.ToArray(typeof(MemberMapping));

                if (mapping.BaseMapping == null) mapping.BaseMapping = GetRootMapping();

                if (mapping.XmlnsMember != null && mapping.BaseMapping.HasXmlnsMember)
                    throw new InvalidOperationException(Res.GetString(Res.XmlMultipleXmlns, model.Type.FullName));

                IncludeTypes(model.Type);
            }
            return mapping;
        }
 MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlReflectionMember[] xmlReflectionMembers, XmlSchemaForm form) {
     SoapAttributes a = xmlReflectionMember.SoapAttributes;
     if (a.SoapIgnore) return null;
     MemberMapping member = new MemberMapping();
     member.IsSoap = true;
     member.Name = xmlReflectionMember.MemberName;
     bool checkSpecified = XmlReflectionImporter.FindSpecifiedMember(xmlReflectionMember.MemberName, xmlReflectionMembers) != null;
     FieldModel model = new FieldModel(xmlReflectionMember.MemberName, xmlReflectionMember.MemberType, typeScope.GetTypeDesc(xmlReflectionMember.MemberType), checkSpecified, false);
     member.CheckShouldPersist = model.CheckShouldPersist;
     member.CheckSpecified = model.CheckSpecified;
     member.ReadOnly = model.ReadOnly; // || !model.FieldTypeDesc.HasDefaultConstructor;
     ImportAccessorMapping(member, model, a, ns, form);
     if (xmlReflectionMember.OverrideIsNullable)
         member.Elements[0].IsNullable = false;
     return member;
 }
Ejemplo n.º 52
0
        ArrayMapping ImportArrayLikeMapping(ArrayModel model, string ns, XmlSchemaForm form) {
            ArrayMapping mapping = new ArrayMapping();
            mapping.TypeDesc = model.TypeDesc;
            if (savedArrayItemAttributes == null)
                savedArrayItemAttributes = new XmlArrayItemAttributes();
            if (CountAtLevel(savedArrayItemAttributes, arrayNestingLevel) == 0)
                savedArrayItemAttributes.Add(CreateArrayItemAttribute(typeScope.GetTypeDesc(model.Element.Type), arrayNestingLevel));
            CreateArrayElementsFromAttributes(mapping, savedArrayItemAttributes, model.Element.Type, savedArrayNamespace == null ? ns : savedArrayNamespace, form);
            SetArrayMappingType(mapping, ns);

            // reconcile accessors now that we have the ArrayMapping namespace
            for (int i = 0; i < mapping.Elements.Length; i++) {
                mapping.Elements[i] = ReconcileLocalAccessor(mapping.Elements[i], mapping.Namespace);
            }

            IncludeTypes(model.Type);

            // in the case of an ArrayMapping we can have more that one mapping correspond to a type
            // examples of that are ArrayList and object[] both will map tp ArrayOfur-type
            // so we create a link list for all mappings of the same XSD type
            ArrayMapping existingMapping = (ArrayMapping)types[mapping.TypeName, mapping.Namespace];
            if (existingMapping != null) {
                ArrayMapping first = existingMapping;
                while (existingMapping != null) {
                    if (existingMapping.TypeDesc == model.TypeDesc)
                        return existingMapping;
                    existingMapping = existingMapping.Next;
                }
                mapping.Next = first;
                types[mapping.TypeName, mapping.Namespace] = mapping;
                return mapping;
            }
            typeScope.AddTypeMapping(mapping);
            types.Add(mapping.TypeName, mapping.Namespace, mapping);
            return mapping;
        }
 private void SetSchemaDefaults(XmlSchema schema)
 {
     if (schema.BlockDefault == XmlSchemaDerivationMethod.All)
     {
         this.blockDefault = XmlSchemaDerivationMethod.All;
     }
     else if (schema.BlockDefault == XmlSchemaDerivationMethod.None)
     {
         this.blockDefault = XmlSchemaDerivationMethod.Empty;
     }
     else
     {
         if ((schema.BlockDefault & ~(XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Substitution)) != XmlSchemaDerivationMethod.Empty)
         {
             base.SendValidationEvent("Sch_InvalidBlockDefaultValue", schema);
         }
         this.blockDefault = schema.BlockDefault & (XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Substitution);
     }
     if (schema.FinalDefault == XmlSchemaDerivationMethod.All)
     {
         this.finalDefault = XmlSchemaDerivationMethod.All;
     }
     else if (schema.FinalDefault == XmlSchemaDerivationMethod.None)
     {
         this.finalDefault = XmlSchemaDerivationMethod.Empty;
     }
     else
     {
         if ((schema.FinalDefault & ~(XmlSchemaDerivationMethod.Union | XmlSchemaDerivationMethod.List | XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension)) != XmlSchemaDerivationMethod.Empty)
         {
             base.SendValidationEvent("Sch_InvalidFinalDefaultValue", schema);
         }
         this.finalDefault = schema.FinalDefault & (XmlSchemaDerivationMethod.Union | XmlSchemaDerivationMethod.List | XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Extension);
     }
     this.elementFormDefault = schema.ElementFormDefault;
     if (this.elementFormDefault == XmlSchemaForm.None)
     {
         this.elementFormDefault = XmlSchemaForm.Unqualified;
     }
     this.attributeFormDefault = schema.AttributeFormDefault;
     if (this.attributeFormDefault == XmlSchemaForm.None)
     {
         this.attributeFormDefault = XmlSchemaForm.Unqualified;
     }
 }
Ejemplo n.º 54
0
 MemberMapping ImportFieldMapping(StructModel parent, FieldModel model, XmlAttributes a, string ns, XmlSchemaForm form) {
     MemberMapping member = new MemberMapping();
     member.Name = model.Name;
     member.CheckShouldPersist = model.CheckShouldPersist;
     member.CheckSpecified = model.CheckSpecified;
     member.ReadOnly = model.ReadOnly || !model.FieldTypeDesc.HasDefaultConstructor;
     Type choiceIdentifierType = null;
     if (a.XmlChoiceIdentifier != null) {
         choiceIdentifierType = GetChoiceIdentifierType(a.XmlChoiceIdentifier, parent, model.FieldTypeDesc.IsArrayLike, model.Name);
     }
     ImportAccessorMapping(member, model, a, ns, form, choiceIdentifierType);
     return member;
 }