Inheritance: XmlMapping
Example #1
0
		public void RegisterClrType (XmlTypeMapping map, Type type, string ns)
		{
			if (type == typeof(object)) ns = "";
			string mapKey = type.FullName + "/" + ns;
			if (!_clrTypes.ContainsKey (mapKey))
				_clrTypes.Add (mapKey, map);
		}
        /// <include file='doc\XmlCodeExporter.uex' path='docs/doc[@for="XmlCodeExporter.ExportTypeMapping"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void ExportTypeMapping(XmlTypeMapping xmlTypeMapping) {
            xmlTypeMapping.CheckShallow();
            CheckScope(xmlTypeMapping.Scope);
            if (xmlTypeMapping.Accessor.Any) throw new InvalidOperationException(Res.GetString(Res.XmlIllegalWildcard));

            ExportElement(xmlTypeMapping.Accessor);
        }
Example #3
0
 /// <include file='doc\XmlSchemaExporter.uex' path='docs/doc[@for="XmlSchemaExporter.ExportTypeMapping"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public void ExportTypeMapping(XmlTypeMapping xmlTypeMapping)
 {
     xmlTypeMapping.CheckShallow();
     CheckScope(xmlTypeMapping.Scope);
     ExportElement(xmlTypeMapping.Accessor);
     ExportRootIfNecessary(xmlTypeMapping.Scope);
 }
 public static XmlSerializer Create(XmlTypeMapping xmlTypeMapping)
 {
     XmlSerializer xs = _factory.CreateSerializer(xmlTypeMapping);
     if (xs == null)
         xs = new XmlSerializer(xmlTypeMapping);
     return xs;
 }
		public static void Print(XmlTypeMapping tm)
		{
			Console.WriteLine("/XmlTypeMapping:");
			Console.WriteLine("ElementName: {0} ", tm.ElementName);
			Console.WriteLine("Namespace: {0} ", tm.Namespace);
			Console.WriteLine("TypeName: {0} ", tm.TypeName);
			Console.WriteLine("FullTypeName: {0} ", tm.TypeFullName);
		}
		public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlTypeMapping member, string ns)
		{
			if (member.Namespace != ns && member.Namespace != "") {
				CodeAttributeDeclaration ratt = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlRoot");
				ratt.Arguments.Add (MapCodeGenerator.GetArg (member.ElementName));
				ratt.Arguments.Add (MapCodeGenerator.GetArg ("Namespace", member.Namespace));
				ratt.Arguments.Add (MapCodeGenerator.GetArg ("IsNullable", member.IsNullable));
				metadata.Add (ratt);
			}
		}
		public XmlSerializer CreateSerializer (XmlTypeMapping xmlTypeMapping)
		{
			lock (serializersBySource) 
			{
				XmlSerializer ser = (XmlSerializer) serializersBySource [xmlTypeMapping.Source];
				if (ser == null) {
					ser = new XmlSerializer (xmlTypeMapping);
					serializersBySource [xmlTypeMapping.Source] = ser;
				}
				return ser;
			}
		}
 object ReadXmlSerializableElement(XmlTypeMapping typeMap, bool isNullable)
 {
     Reader.MoveToContent();
     if (Reader.NodeType == XmlNodeType.Element)
     {
         if (Reader.LocalName == typeMap.ElementName && Reader.NamespaceURI == typeMap.Namespace)
         {
             object ob = Activator.CreateInstance(typeMap.TypeData.Type, true);
             return(ReadSerializable((IXmlSerializable)ob));
         }
         else
         {
             throw CreateUnknownNodeException();
         }
     }
     else
     {
         UnknownNode(null);
         return(null);
     }
 }
Example #9
0
        protected override void InitCallbacks()
        {
            ArrayList relatedMaps = this._typeMap.RelatedMaps;

            if (relatedMaps != null)
            {
                foreach (object obj in relatedMaps)
                {
                    XmlTypeMapping xmlTypeMapping = (XmlTypeMapping)obj;
                    XmlSerializationWriterInterpreter.CallbackInfo @object = new XmlSerializationWriterInterpreter.CallbackInfo(this, xmlTypeMapping);
                    if (xmlTypeMapping.TypeData.SchemaType == SchemaTypes.Enum)
                    {
                        base.AddWriteCallback(xmlTypeMapping.TypeData.Type, xmlTypeMapping.XmlType, xmlTypeMapping.Namespace, new XmlSerializationWriteCallback(@object.WriteEnum));
                    }
                    else
                    {
                        base.AddWriteCallback(xmlTypeMapping.TypeData.Type, xmlTypeMapping.XmlType, xmlTypeMapping.Namespace, new XmlSerializationWriteCallback(@object.WriteObject));
                    }
                }
            }
        }
Example #10
0
        void ExportEnumCode(XmlTypeMapping map)
        {
            if (IsMapExported(map))
            {
                return;
            }

            CodeTypeDeclaration codeEnum = new CodeTypeDeclaration(map.TypeData.TypeName);

            SetMapExported(map, codeEnum);

            codeEnum.Attributes = MemberAttributes.Public;
            codeEnum.IsEnum     = true;
            AddCodeType(codeEnum, map.Documentation);

            GenerateEnum(map, codeEnum);
            EnumMap emap = (EnumMap)map.ObjectMap;

            if (emap.IsFlags)
            {
                codeEnum.CustomAttributes.Add(new CodeAttributeDeclaration("System.Flags"));
            }

            int flag = 1;

            foreach (EnumMap.EnumMapMember emem in emap.Members)
            {
                CodeMemberField codeField = new CodeMemberField("", emem.EnumName);
                if (emap.IsFlags)
                {
                    codeField.InitExpression = new CodePrimitiveExpression(flag);
                    flag *= 2;
                }

                AddComments(codeField, emem.Documentation);

                GenerateEnumItem(codeField, emem);
                codeEnum.Members.Add(codeField);
            }
        }
Example #11
0
        void ExportEnumSchema(XmlTypeMapping map)
        {
            if (IsMapExported(map))
            {
                return;
            }
            SetMapExported(map);

            XmlSchema           schema = GetSchema(map.XmlTypeNamespace);
            XmlSchemaSimpleType stype  = new XmlSchemaSimpleType();

            stype.Name = map.ElementName;
            schema.Items.Add(stype);

            XmlSchemaSimpleTypeRestriction rest = new XmlSchemaSimpleTypeRestriction();

            rest.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
            EnumMap emap = (EnumMap)map.ObjectMap;

            foreach (EnumMap.EnumMapMember emem in emap.Members)
            {
                XmlSchemaEnumerationFacet ef = new XmlSchemaEnumerationFacet();
                ef.Value = emem.XmlName;
                rest.Facets.Add(ef);
            }

            if (emap.IsFlags)
            {
                XmlSchemaSimpleTypeList slist           = new XmlSchemaSimpleTypeList();
                XmlSchemaSimpleType     restrictionType = new XmlSchemaSimpleType();
                restrictionType.Content = rest;
                slist.ItemType          = restrictionType;
                stype.Content           = slist;
            }
            else
            {
                stype.Content = rest;
            }
        }
Example #12
0
        /// <include file='doc\XmlSerializerFactory.uex' path='docs/doc[@for="XmlSerializerFactory.CreateSerializer1"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlSerializer CreateSerializer(Type type, string defaultNamespace)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            TempAssembly   tempAssembly = s_cache[defaultNamespace, type];
            XmlTypeMapping mapping      = null;

            if (tempAssembly == null)
            {
                lock (s_cache)
                {
                    tempAssembly = s_cache[defaultNamespace, type];
                    if (tempAssembly == null)
                    {
                        XmlSerializerImplementation contract;
                        Assembly assembly = TempAssembly.LoadGeneratedAssembly(type, defaultNamespace, out contract);
                        if (assembly == null)
                        {
                            // need to reflect and generate new serialization assembly
                            XmlReflectionImporter importer = new XmlReflectionImporter(defaultNamespace);
                            mapping      = importer.ImportTypeMapping(type, null, defaultNamespace);
                            tempAssembly = XmlSerializer.GenerateTempAssembly(mapping, type, defaultNamespace);
                        }
                        else
                        {
                            tempAssembly = new TempAssembly(contract);
                        }
                        s_cache.Add(defaultNamespace, type, tempAssembly);
                    }
                }
            }
            if (mapping == null)
            {
                mapping = XmlReflectionImporter.GetTopLevelMapping(type, defaultNamespace);
            }
            return((XmlSerializer)tempAssembly.Contract.GetSerializer(type));
        }
Example #13
0
        private void GenerateTypeElement(object o, XmlTypeMapping xmlMapping)
        {
            ElementAccessor element = xmlMapping.Accessor;
            TypeMapping     mapping = element.Mapping;

            WriteStartDocument();
            if (o == null)
            {
                if (element.IsNullable)
                {
                    if (mapping.IsSoap)
                    {
                        throw new PlatformNotSupportedException();
                    }
                    else
                    {
                        WriteNullTagLiteral(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
                    }
                }
                else
                {
                    WriteEmptyTag(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
                }

                return;
            }

            if (!mapping.TypeDesc.IsValueType && !mapping.TypeDesc.Type.GetTypeInfo().IsPrimitive)
            {
                TopLevelElement();
            }

            WriteMember(o, null, new ElementAccessor[] { element }, null, null, mapping.TypeDesc, !element.IsSoap, xmlMapping);

            if (mapping.IsSoap)
            {
                WriteReferencedElements();
            }
        }
 private string GetMapKey(XmlTypeMapping map)
 {
     if (map.TypeData.IsListType)
     {
         return(string.Concat(new string[]
         {
             this.GetArrayKeyName(map.TypeData),
             " ",
             map.XmlType,
             " ",
             map.XmlTypeNamespace
         }));
     }
     return(string.Concat(new string[]
     {
         map.TypeData.FullTypeName,
         " ",
         map.XmlType,
         " ",
         map.XmlTypeNamespace
     }));
 }
        private void GenerateTypeElement(object o, XmlTypeMapping xmlMapping)
        {
            ElementAccessor element = xmlMapping.Accessor;
            TypeMapping mapping = element.Mapping;

            WriteStartDocument();
            if (o == null)
            {
                if (element.IsNullable)
                {
                    if (mapping.IsSoap)
                    {
                        throw new PlatformNotSupportedException();
                    }
                    else
                    {
                        WriteNullTagLiteral(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
                    }
                }
                else
                {
                    WriteEmptyTag(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
                }

                return;
            }

            if (!mapping.TypeDesc.IsValueType && !mapping.TypeDesc.Type.GetTypeInfo().IsPrimitive)
            {
                TopLevelElement();
            }

            WriteMember(o, null, new ElementAccessor[] { element }, null, null, mapping.TypeDesc, !element.IsSoap, xmlMapping);

            if (mapping.IsSoap)
            {
                throw new PlatformNotSupportedException();
            }
        }
Example #16
0
        protected override void GenerateClass(XmlTypeMapping map, CodeTypeDeclaration codeClass, bool isTopLevel)
        {
            CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Xml.Serialization.XmlTypeAttribute");

            if (map.XmlType != map.TypeData.TypeName)
            {
                att.Arguments.Add(GetArg(map.XmlType));
            }
            if (map.XmlTypeNamespace != "")
            {
                att.Arguments.Add(GetArg("Namespace", map.XmlTypeNamespace));
            }
            if (!map.IncludeInSchema)
            {
                att.Arguments.Add(GetArg("IncludeInSchema", false));
            }
            AddCustomAttribute(codeClass, att, false);

            CodeAttributeDeclaration ratt = new CodeAttributeDeclaration("System.Xml.Serialization.XmlRootAttribute");

            if (map.ElementName != map.XmlType)
            {
                ratt.Arguments.Add(GetArg(map.ElementName));
            }
            if (isTopLevel)
            {
                ratt.Arguments.Add(GetArg("Namespace", map.Namespace));
                ratt.Arguments.Add(GetArg("IsNullable", map.IsNullable));
            }
            else
            {
                if (map.Namespace != "")
                {
                    ratt.Arguments.Add(GetArg("Namespace", map.Namespace));
                }
            }
            AddCustomAttribute(codeClass, ratt, isTopLevel);
        }
        XmlTypeMapping ImportEnumMapping(TypeData typeData, string defaultNamespace)
        {
            Type           type = typeData.Type;
            XmlTypeMapping map  = helper.GetRegisteredClrType(type, GetTypeNamespace(typeData, defaultNamespace));

            if (map != null)
            {
                return(map);
            }

            ReflectionHelper.CheckSerializableType(type, false);

            map = CreateTypeMapping(typeData, null, defaultNamespace);
            helper.RegisterClrType(map, type, map.Namespace);

            map.MultiReferenceType = true;

            string [] names = Enum.GetNames(type);
            EnumMap.EnumMapMember[] members = new EnumMap.EnumMapMember[names.Length];
            for (int n = 0; n < names.Length; n++)
            {
                FieldInfo field   = type.GetField(names[n]);
                string    xmlName = names[n];
                object[]  atts    = field.GetCustomAttributes(typeof(SoapEnumAttribute), false);
                if (atts.Length > 0)
                {
                    xmlName = ((SoapEnumAttribute)atts[0]).Name;
                }
                long value = ((IConvertible)field.GetValue(null)).ToInt64(CultureInfo.InvariantCulture);
                members[n] = new EnumMap.EnumMapMember(XmlConvert.EncodeLocalName(xmlName), names[n], value);
            }

            bool isFlags = type.IsDefined(typeof(FlagsAttribute), false);

            map.ObjectMap = new EnumMap(members, isFlags);
            ImportTypeMapping(typeof(object), defaultNamespace).DerivedTypes.Add(map);
            return(map);
        }
        private void ExportEnumSchema(XmlTypeMapping map)
        {
            if (this.IsMapExported(map))
            {
                return;
            }
            this.SetMapExported(map);
            XmlSchema           schema = this.GetSchema(map.XmlTypeNamespace);
            XmlSchemaSimpleType xmlSchemaSimpleType = new XmlSchemaSimpleType();

            xmlSchemaSimpleType.Name = map.ElementName;
            schema.Items.Add(xmlSchemaSimpleType);
            XmlSchemaSimpleTypeRestriction xmlSchemaSimpleTypeRestriction = new XmlSchemaSimpleTypeRestriction();

            xmlSchemaSimpleTypeRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
            EnumMap enumMap = (EnumMap)map.ObjectMap;

            foreach (EnumMap.EnumMapMember enumMapMember in enumMap.Members)
            {
                XmlSchemaEnumerationFacet xmlSchemaEnumerationFacet = new XmlSchemaEnumerationFacet();
                xmlSchemaEnumerationFacet.Value = enumMapMember.XmlName;
                xmlSchemaSimpleTypeRestriction.Facets.Add(xmlSchemaEnumerationFacet);
            }
            if (enumMap.IsFlags)
            {
                xmlSchemaSimpleType.Content = new XmlSchemaSimpleTypeList
                {
                    ItemType = new XmlSchemaSimpleType
                    {
                        Content = xmlSchemaSimpleTypeRestriction
                    }
                };
            }
            else
            {
                xmlSchemaSimpleType.Content = xmlSchemaSimpleTypeRestriction;
            }
        }
        internal XmlTypeMapping GetRealTypeMap(Type objectType)
        {
            if (TypeData.SchemaType == SchemaTypes.Enum)
            {
                return(this);
            }

            // Returns the map for a subtype of this map's type
            if (TypeData.Type == objectType)
            {
                return(this);
            }
            for (int n = 0; n < _derivedTypes.Count; n++)
            {
                XmlTypeMapping map = (XmlTypeMapping)_derivedTypes[n];
                if (map.TypeData.Type == objectType)
                {
                    return(map);
                }
            }

            return(null);
        }
Example #20
0
        void ExportMapCode(XmlTypeMapping map, bool isTopLevel)
        {
            switch (map.TypeData.SchemaType)
            {
            case SchemaTypes.Enum:
                ExportEnumCode(map, isTopLevel);
                break;

            case SchemaTypes.Array:
                ExportArrayCode(map);
                break;

            case SchemaTypes.Class:
                ExportClassCode(map, isTopLevel);
                break;

            case SchemaTypes.XmlSerializable:
            case SchemaTypes.XmlNode:
            case SchemaTypes.Primitive:
                // Ignore
                break;
            }
        }
Example #21
0
        private object GenerateTypeElement(XmlTypeMapping xmlTypeMapping)
        {
            ElementAccessor element = xmlTypeMapping.Accessor;
            TypeMapping     mapping = element.Mapping;

            Reader.MoveToContent();

            MemberMapping member = new MemberMapping();

            member.TypeDesc = mapping.TypeDesc;
            member.Elements = new ElementAccessor[] { element };

            UnknownNodeAction elementElseAction = UnknownNodeAction.CreateUnknownNodeException;
            UnknownNodeAction elseAction        = UnknownNodeAction.ReadUnknownNode;

            object o             = null;
            Member tempMember    = null;
            var    currentMember = new Member(member);

            WriteMemberElements(ref o, null /*collectionMember*/, out tempMember, new Member[] { currentMember }, elementElseAction, elseAction, element.Any ? currentMember : null, null, xmlTypeMapping);

            return(o);
        }
Example #22
0
        private object ReadListString(XmlTypeMapping typeMap, string values)
        {
            Type    type    = typeMap.TypeData.Type;
            ListMap listMap = (ListMap)typeMap.ObjectMap;

            values = values.Trim();
            if (values == string.Empty)
            {
                return(Array.CreateInstance(type.GetElementType(), 0));
            }
            string[] array = values.Split(new char[]
            {
                ' '
            });
            Array array2 = Array.CreateInstance(type.GetElementType(), array.Length);
            XmlTypeMapElementInfo xmlTypeMapElementInfo = (XmlTypeMapElementInfo)listMap.ItemInfo[0];

            for (int i = 0; i < array.Length; i++)
            {
                array2.SetValue(this.GetValueFromXmlString(array[i], xmlTypeMapElementInfo.TypeData, xmlTypeMapElementInfo.MappedType), i);
            }
            return(array2);
        }
        public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location, Evidence evidence)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (location != null || evidence != null)
            {
                DemandForUserLocationOrEvidence();
            }

            XmlReflectionImporter importer = new XmlReflectionImporter(overrides, defaultNamespace);

            for (int i = 0; i < extraTypes.Length; i++)
            {
                importer.IncludeType(extraTypes[i]);
            }
            XmlTypeMapping mapping      = importer.ImportTypeMapping(type, root, defaultNamespace);
            TempAssembly   tempAssembly = XmlSerializer.GenerateTempAssembly(mapping, type, defaultNamespace, location, evidence);

            return((XmlSerializer)tempAssembly.Contract.TypedSerializers[mapping.Key]);
        }
        object ReadEncodedObject(XmlTypeMapping typeMap)
        {
            object ob = null;

            Reader.MoveToContent();
            if (Reader.NodeType == System.Xml.XmlNodeType.Element)
            {
                if (Reader.LocalName == typeMap.ElementName && Reader.NamespaceURI == typeMap.Namespace)
                {
                    ob = ReadReferencedElement();
                }
                else
                {
                    throw CreateUnknownNodeException();
                }
            }
            else
            {
                UnknownNode(null);
            }

            ReadReferencedElements();
            return(ob);
        }
        object ReadListString(XmlTypeMapping typeMap, string values)
        {
            Type    listType = typeMap.TypeData.Type;
            ListMap listMap  = (ListMap)typeMap.ObjectMap;

            values = values.Trim();

            if (values == string.Empty)
            {
                return(Array.CreateInstance(listType.GetElementType(), 0));
            }

            string[] valueArray = values.Split(' ');
            Array    list       = Array.CreateInstance(listType.GetElementType(), valueArray.Length);

            XmlTypeMapElementInfo info = (XmlTypeMapElementInfo)listMap.ItemInfo[0];

            for (int index = 0; index < valueArray.Length; index++)
            {
                list.SetValue(GetValueFromXmlString(valueArray[index], info.TypeData, info.MappedType), index);
            }

            return(list);
        }
        public XmlSerializer CreateSerializer(Type type, string defaultNamespace)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            TempAssembly   assembly   = cache[defaultNamespace, type];
            XmlTypeMapping xmlMapping = null;

            if (assembly == null)
            {
                lock (cache)
                {
                    assembly = cache[defaultNamespace, type];
                    if (assembly == null)
                    {
                        XmlSerializerImplementation implementation;
                        if (TempAssembly.LoadGeneratedAssembly(type, defaultNamespace, out implementation) == null)
                        {
                            xmlMapping = new XmlReflectionImporter(defaultNamespace).ImportTypeMapping(type, null, defaultNamespace);
                            assembly   = XmlSerializer.GenerateTempAssembly(xmlMapping, type, defaultNamespace);
                        }
                        else
                        {
                            assembly = new TempAssembly(implementation);
                        }
                        cache.Add(defaultNamespace, type, assembly);
                    }
                }
            }
            if (xmlMapping == null)
            {
                xmlMapping = XmlReflectionImporter.GetTopLevelMapping(type, defaultNamespace);
            }
            return(assembly.Contract.GetSerializer(type));
        }
Example #27
0
 public Exception CreateError(XmlTypeMapping map, string message)
 {
     return(new InvalidOperationException("There was an error reflecting '" + map.TypeFullName + "': " + message));
 }
		protected override void GenerateEnum (XmlTypeMapping map, CodeTypeDeclaration codeEnum)
		{
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapType");
			if (map.XmlType != map.TypeData.TypeName) att.Arguments.Add (GetArg (map.XmlType));
			if (map.XmlTypeNamespace != "") att.Arguments.Add (GetArg ("Namespace", map.XmlTypeNamespace));
			AddCustomAttribute (codeEnum, att, false);
		}		
Example #29
0
 public void ExportTypeMapping(XmlTypeMapping xmlTypeMapping)
 {
     codeGenerator.ExportTypeMapping(xmlTypeMapping, true);
 }
Example #30
0
		void RegisterMapFixup (XmlTypeMapping map, XmlQualifiedName typeQName, XmlSchemaComplexType stype)
		{
			// This check is introduced for bug #650117, but might be too wide to catch erroneous cases...
			if (fixup_registered_types.Contains (stype))
				throw new InvalidOperationException (String.Format ("Circular dependency for schema type {0} in namespace {1}", map.ElementName, map.Namespace));
			fixup_registered_types.Add (stype);
			MapFixup fixup = new MapFixup ();
			fixup.Map = map;
			fixup.SchemaType = stype;
			fixup.TypeName = typeQName;
			pendingMaps.Enqueue (fixup);
		}
Example #31
0
 void SetElementExported(XmlTypeMapping map)
 {
     exportedElements [GetMapKey(map)] = map;
 }
Example #32
0
		void BuildClassMap (XmlTypeMapping map, XmlQualifiedName typeQName, XmlSchemaComplexType stype)
		{
			CodeIdentifiers classIds = new CodeIdentifiers();
			classIds.AddReserved (map.TypeData.TypeName);

			ClassMap cmap = new ClassMap ();
			map.ObjectMap = cmap;
			bool isMixed = stype.IsMixed;

			if (stype.Particle != null)
				ImportParticleComplexContent (typeQName, cmap, stype.Particle, classIds, isMixed);
			else
			{
				if (stype.ContentModel is XmlSchemaSimpleContent) {
					ImportSimpleContent (typeQName, map, (XmlSchemaSimpleContent)stype.ContentModel, classIds, isMixed);
				}
				else if (stype.ContentModel is XmlSchemaComplexContent) {
					ImportComplexContent (typeQName, map, (XmlSchemaComplexContent)stype.ContentModel, classIds, isMixed);
				}
			}

			ImportAttributes (typeQName, cmap, stype.Attributes, stype.AnyAttribute, classIds);
			ImportExtensionTypes (typeQName);

			if (isMixed) AddTextMember (typeQName, cmap, classIds);
			
			AddObjectDerivedMap (map);
		}
Example #33
0
		void SetMapBaseType (XmlTypeMapping map, Type baseType)
		{
			// This method sets the base type for a given map.
			// If the map already inherits from this type, it does nothing.
			
			// Fiirst of all, check if the map already inherits from baseType
				
			XmlTypeMapping topMap = null;
			while (map != null)
			{
				if (map.TypeData.Type == baseType)
					return;
				topMap = map;
				map = map.BaseMap;
			}
			
			// Does not have the requested base type.
			// Then, get/create a map for that base type.

			XmlTypeMapping baseMap = ReflectType (baseType);
			
			// Add this map as a derived map of the base map

			topMap.BaseMap = baseMap;
			baseMap.DerivedTypes.Add (topMap);
			baseMap.DerivedTypes.AddRange (topMap.DerivedTypes);
			
			// Now add the base type fields to all derived maps

			ClassMap baseClassMap = (ClassMap)baseMap.ObjectMap;
			
			ClassMap cmap = (ClassMap)topMap.ObjectMap;
			foreach (XmlTypeMapMember member in baseClassMap.AllMembers)
				cmap.AddMember (member);
				
			foreach (XmlTypeMapping derivedMap in topMap.DerivedTypes)
			{
				cmap = (ClassMap)derivedMap.ObjectMap;
				foreach (XmlTypeMapMember member in baseClassMap.AllMembers)
					cmap.AddMember (member);
			}
		}
Example #34
0
        protected override void GenerateClassInclude(CodeAttributeDeclarationCollection attributes, XmlTypeMapping map)
        {
            CodeAttributeDeclaration iatt = new CodeAttributeDeclaration("System.Xml.Serialization.SoapInclude");

            iatt.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(map.TypeData.FullTypeName)));
            attributes.Add(iatt);
        }
Example #35
0
        XmlQualifiedName ExportArraySchema(XmlTypeMapping map, string defaultNamespace)
        {
            ListMap lmap = (ListMap)map.ObjectMap;

            if (encodedFormat)
            {
                string name, ns, schemaNs;
                lmap.GetArrayType(-1, out name, out ns);
                if (ns == XmlSchema.Namespace)
                {
                    schemaNs = defaultNamespace;
                }
                else
                {
                    schemaNs = ns;
                }

                if (IsMapExported(map))
                {
                    return(new XmlQualifiedName(lmap.GetSchemaArrayName(), schemaNs));
                }
                SetMapExported(map);

                XmlSchema            schema = GetSchema(schemaNs);
                XmlSchemaComplexType stype  = new XmlSchemaComplexType();
                stype.Name = lmap.GetSchemaArrayName();
                schema.Items.Add(stype);

                XmlSchemaComplexContent content = new XmlSchemaComplexContent();
                content.IsMixed    = false;
                stype.ContentModel = content;

                XmlSchemaComplexContentRestriction rest = new XmlSchemaComplexContentRestriction();
                content.Content   = rest;
                rest.BaseTypeName = new XmlQualifiedName("Array", XmlSerializer.EncodingNamespace);
                XmlSchemaAttribute at = new XmlSchemaAttribute();
                rest.Attributes.Add(at);
                at.RefName = new XmlQualifiedName("arrayType", XmlSerializer.EncodingNamespace);

                XmlAttribute arrayType = Document.CreateAttribute("arrayType", XmlSerializer.WsdlNamespace);
                arrayType.Value        = ns + (ns != "" ? ":" : "") + name;
                at.UnhandledAttributes = new XmlAttribute [] { arrayType };
                ImportNamespace(schema, XmlSerializer.WsdlNamespace);

                XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo)lmap.ItemInfo[0];
                if (einfo.MappedType != null)
                {
                    switch (einfo.TypeData.SchemaType)
                    {
                    case SchemaTypes.Enum:
                        ExportEnumSchema(einfo.MappedType);
                        break;

                    case SchemaTypes.Array:
                        ExportArraySchema(einfo.MappedType, schemaNs);
                        break;

                    case SchemaTypes.Class:
                        ExportClassSchema(einfo.MappedType);
                        break;
                    }
                }

                return(new XmlQualifiedName(lmap.GetSchemaArrayName(), schemaNs));
            }
            else
            {
                if (IsMapExported(map))
                {
                    return(new XmlQualifiedName(map.XmlType, map.XmlTypeNamespace));
                }

                SetMapExported(map);
                XmlSchema            schema = GetSchema(map.XmlTypeNamespace);
                XmlSchemaComplexType stype  = new XmlSchemaComplexType();
                stype.Name = map.ElementName;
                schema.Items.Add(stype);

                XmlSchemaParticle spart = GetSchemaArrayElement(schema, lmap.ItemInfo);
                if (spart is XmlSchemaChoice)
                {
                    stype.Particle = spart;
                }
                else
                {
                    XmlSchemaSequence seq = new XmlSchemaSequence();
                    seq.Items.Add(spart);
                    stype.Particle = seq;
                }

                return(new XmlQualifiedName(map.XmlType, map.XmlTypeNamespace));
            }
        }
Example #36
0
        void ExportMembersMapSchema(XmlSchema schema, ClassMap map, XmlTypeMapping baseMap, XmlSchemaObjectCollection outAttributes, out XmlSchemaSequence particle, out XmlSchemaAnyAttribute anyAttribute)
        {
            particle = null;
            XmlSchemaSequence seq = new XmlSchemaSequence();

            ICollection members = map.ElementMembers;

            if (members != null && !map.HasSimpleContent)
            {
                foreach (XmlTypeMapMemberElement member in members)
                {
                    if (baseMap != null && DefinedInBaseMap(baseMap, member))
                    {
                        continue;
                    }

                    Type memType = member.GetType();
                    if (memType == typeof(XmlTypeMapMemberFlatList))
                    {
                        XmlSchemaParticle part = GetSchemaArrayElement(schema, member.ElementInfo);
                        if (part != null)
                        {
                            seq.Items.Add(part);
                        }
                    }
                    else if (memType == typeof(XmlTypeMapMemberAnyElement))
                    {
                        seq.Items.Add(GetSchemaArrayElement(schema, member.ElementInfo));
                    }
                    else if (memType == typeof(XmlTypeMapMemberElement))
                    {
                        GetSchemaElement(schema, (XmlTypeMapElementInfo)member.ElementInfo [0],
                                         member.DefaultValue, true, new XmlSchemaObjectContainer(seq));
                    }
                    else
                    {
                        GetSchemaElement(schema, (XmlTypeMapElementInfo)member.ElementInfo[0],
                                         true, new XmlSchemaObjectContainer(seq));
                    }
                }
            }

            if (seq.Items.Count > 0)
            {
                particle = seq;
            }

            // Write attributes

            ICollection attributes = map.AttributeMembers;

            if (attributes != null)
            {
                foreach (XmlTypeMapMemberAttribute attr in attributes)
                {
                    if (baseMap != null && DefinedInBaseMap(baseMap, attr))
                    {
                        continue;
                    }
                    outAttributes.Add(GetSchemaAttribute(schema, attr, true));
                }
            }

            XmlTypeMapMember anyAttrMember = map.DefaultAnyAttributeMember;

            if (anyAttrMember != null)
            {
                anyAttribute = new XmlSchemaAnyAttribute();
            }
            else
            {
                anyAttribute = null;
            }
        }
Example #37
0
        bool HasMixedContent(XmlTypeMapping map)
        {
            ClassMap cmap = (ClassMap)map.ObjectMap;

            return(cmap.XmlTextCollector != null && (map.BaseMap == null || !DefinedInBaseMap(map.BaseMap, cmap.XmlTextCollector)));
        }
Example #38
0
        void ExportClassSchema(XmlTypeMapping map)
        {
            if (IsMapExported(map))
            {
                return;
            }
            SetMapExported(map);

            if (map.TypeData.Type == typeof(object))
            {
                foreach (XmlTypeMapping dmap in map.DerivedTypes)
                {
                    if (dmap.TypeData.SchemaType == SchemaTypes.Class)
                    {
                        ExportClassSchema(dmap);
                    }
                }
                return;
            }

            XmlSchema            schema = GetSchema(map.XmlTypeNamespace);
            XmlSchemaComplexType stype  = new XmlSchemaComplexType();

            stype.Name = map.XmlType;
            schema.Items.Add(stype);

            ClassMap cmap = (ClassMap)map.ObjectMap;

            if (cmap.HasSimpleContent)
            {
                XmlSchemaSimpleContent simple = new XmlSchemaSimpleContent();
                stype.ContentModel = simple;
                XmlSchemaSimpleContentExtension ext = new XmlSchemaSimpleContentExtension();
                simple.Content = ext;
                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                ExportMembersMapSchema(schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
                ext.AnyAttribute = anyAttribute;
                if (map.BaseMap == null)
                {
                    ext.BaseTypeName = cmap.SimpleContentBaseType;
                }
                else
                {
                    ext.BaseTypeName = new XmlQualifiedName(map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
                    ImportNamespace(schema, map.BaseMap.XmlTypeNamespace);
                    ExportClassSchema(map.BaseMap);
                }
            }
            else if (map.BaseMap != null && map.BaseMap.IncludeInSchema)
            {
                XmlSchemaComplexContent          cstype = new XmlSchemaComplexContent();
                XmlSchemaComplexContentExtension ext    = new XmlSchemaComplexContentExtension();
                ext.BaseTypeName   = new XmlQualifiedName(map.BaseMap.XmlType, map.BaseMap.XmlTypeNamespace);
                cstype.Content     = ext;
                stype.ContentModel = cstype;

                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                ExportMembersMapSchema(schema, cmap, map.BaseMap, ext.Attributes, out particle, out anyAttribute);
                ext.Particle     = particle;
                ext.AnyAttribute = anyAttribute;
                stype.IsMixed    = HasMixedContent(map);
                cstype.IsMixed   = BaseHasMixedContent(map);

                ImportNamespace(schema, map.BaseMap.XmlTypeNamespace);
                ExportClassSchema(map.BaseMap);
            }
            else
            {
                XmlSchemaSequence     particle;
                XmlSchemaAnyAttribute anyAttribute;
                ExportMembersMapSchema(schema, cmap, map.BaseMap, stype.Attributes, out particle, out anyAttribute);
                stype.Particle     = particle;
                stype.AnyAttribute = anyAttribute;
                stype.IsMixed      = cmap.XmlTextCollector != null;
            }

            foreach (XmlTypeMapping dmap in map.DerivedTypes)
            {
                if (dmap.TypeData.SchemaType == SchemaTypes.Class)
                {
                    ExportClassSchema(dmap);
                }
            }
        }
Example #39
0
		XmlTypeMapping CreateSystemMap (TypeData typeData)
		{
			XmlTypeMapping map = new XmlTypeMapping (typeData.XmlType, XmlSchema.Namespace, typeData, typeData.XmlType, XmlSchema.Namespace);
			map.IncludeInSchema = false;
			map.ObjectMap = new ClassMap ();
			dataMappedTypes [typeData] = map;
			return map;
		}
Example #40
0
		void RegisterDerivedMap (XmlTypeMapping map, XmlTypeMapping derivedMap)
		{
			map.DerivedTypes.Add (derivedMap);
			map.DerivedTypes.AddRange (derivedMap.DerivedTypes);
			
			if (map.BaseMap != null)
				RegisterDerivedMap (map.BaseMap, derivedMap);
			else {
				XmlTypeMapping obmap = ImportTypeMapping (typeof(object));
				if (obmap != map)
					obmap.DerivedTypes.Add (derivedMap);
			}
		}
Example #41
0
		void RegisterTypeMapping (XmlQualifiedName qname, TypeData typeData, XmlTypeMapping map)
		{
			// Primitive types with a forced base class are stored in a different table.
			// In this way it is possible to have two maps for primitive types: one with
			// the forced base class (returned by ImportDerivedTypeMapping) and one
			// with the regular primitive map.
			
			dataMappedTypes [typeData] = map;
			if (IsPrimitiveTypeNamespace (qname.Namespace) && !map.IsSimpleType)
				primitiveDerivedMappedTypes [qname] = map;
			else
				mappedTypes [qname] = map;
		}
 public XmlSerializer CreateSerializer(XmlTypeMapping xmlTypeMapping)
 {
     return(new XmlSerializer(xmlTypeMapping));
 }
Example #43
0
		XmlMemberMapping ImportMemberMapping (string name, string ns, bool isNullable, TypeData type, XmlTypeMapping emap, int order)
		{
			XmlTypeMapMemberElement mapMem;
			
			if (type.IsListType)
				mapMem = new XmlTypeMapMemberList ();
			else
				mapMem = new XmlTypeMapMemberElement ();
			
			mapMem.Name = name;
			mapMem.TypeData = type;
			mapMem.ElementInfo.Add (CreateElementInfo (ns, mapMem, name, type, isNullable, XmlSchemaForm.None, emap, order));
			return new XmlMemberMapping (name, ns, mapMem, encodedFormat);
		}
 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer5"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer(XmlTypeMapping xmlTypeMapping)
 {
     tempAssembly = GenerateTempAssembly(xmlTypeMapping);
     this.mapping = xmlTypeMapping;
 }
Example #45
0
		void BuildPendingMap (XmlTypeMapping map)
		{
			if (map.ObjectMap != null) return;

			foreach (MapFixup fixup in pendingMaps)
			{
				if (fixup.Map == map) {
					BuildClassMap (fixup.Map, fixup.TypeName, fixup.SchemaType);
					return;
				}
			}
			throw new InvalidOperationException ("Can't complete map of type " + map.XmlType + " : " + map.Namespace);
		}
Example #46
0
 void SetMapExported(XmlTypeMapping map)
 {
     exportedMaps [GetMapKey(map)] = map;
 }
Example #47
0
		XmlTypeMapping CreateTypeMapping (TypeData typeData, XmlRootAttribute root, string defaultXmlType, string defaultNamespace)
		{
			string rootNamespace = defaultNamespace;
			string typeNamespace = null;
			string elementName;
			bool includeInSchema = true;
			XmlAttributes atts = null;
			bool nullable = CanBeNull (typeData);

			if (defaultXmlType == null) defaultXmlType = typeData.XmlType;

			if (!typeData.IsListType)
			{
				if (attributeOverrides != null) 
					atts = attributeOverrides[typeData.Type];

				if (atts != null && typeData.SchemaType == SchemaTypes.Primitive)
					throw new InvalidOperationException ("XmlRoot and XmlType attributes may not be specified for the type " + typeData.FullTypeName);
			}

			if (atts == null) 
				atts = new XmlAttributes (typeData.Type);

			if (atts.XmlRoot != null && root == null)
				root = atts.XmlRoot;

			if (atts.XmlType != null)
			{
				if (atts.XmlType.Namespace != null)
					typeNamespace = atts.XmlType.Namespace;

				if (atts.XmlType.TypeName != null && atts.XmlType.TypeName != string.Empty)
					defaultXmlType = XmlConvert.EncodeLocalName (atts.XmlType.TypeName);
					
				includeInSchema = atts.XmlType.IncludeInSchema;
			}

			elementName = defaultXmlType;

			if (root != null)
			{
				if (root.ElementName.Length != 0)
					elementName = XmlConvert.EncodeLocalName(root.ElementName);
				if (root.Namespace != null)
					rootNamespace = root.Namespace;
				nullable = root.IsNullable;
			}

			if (rootNamespace == null) rootNamespace = "";
			if (typeNamespace == null) typeNamespace = rootNamespace;
			
			XmlTypeMapping map;
			switch (typeData.SchemaType) {
				case SchemaTypes.XmlSerializable:
					map = new XmlSerializableMapping (root, elementName, rootNamespace, typeData, defaultXmlType, typeNamespace);
					break;
				case SchemaTypes.Primitive:
					if (!typeData.IsXsdType)
						map = new XmlTypeMapping (elementName, rootNamespace, 
							typeData, defaultXmlType, XmlSerializer.WsdlTypesNamespace);
					else
						map = new XmlTypeMapping (elementName, rootNamespace, 
							typeData, defaultXmlType, typeNamespace);
					break;
				default:
					map = new XmlTypeMapping (elementName, rootNamespace, typeData, defaultXmlType, typeNamespace);
					break;
			}

			map.IncludeInSchema = includeInSchema;
			map.IsNullable = nullable;
			relatedMaps.Add (map);
			
			return map;
		}
        /// <include file='doc\XmlSerializerFactory.uex' path='docs/doc[@for="XmlSerializerFactory.CreateSerializer5"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlSerializer CreateSerializer(XmlTypeMapping xmlTypeMapping)
        {
            TempAssembly tempAssembly = XmlSerializer.GenerateTempAssembly(xmlTypeMapping);

            return((XmlSerializer)tempAssembly.Contract.TypedSerializers[xmlTypeMapping.Key]);
        }
		CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, HttpOperationBinding httpOper, XmlMembersMapping inputMembers, XmlTypeMapping outputMember)
		{
			CodeIdentifiers pids = new CodeIdentifiers ();
			CodeMemberMethod method = new CodeMemberMethod ();
			CodeMemberMethod methodBegin = new CodeMemberMethod ();
			CodeMemberMethod methodEnd = new CodeMemberMethod ();
			method.Attributes = MemberAttributes.Public;
			methodBegin.Attributes = MemberAttributes.Public;
			methodEnd.Attributes = MemberAttributes.Public;
			
			// Find unique names for temporary variables
			
			for (int n=0; n<inputMembers.Count; n++)
				pids.AddUnique (inputMembers[n].MemberName, inputMembers[n]);

			string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult");
			string varCallback = pids.AddUnique ("callback","callback");
			string varAsyncState = pids.AddUnique ("asyncState","asyncState");

			string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name),method);

			method.Name = Operation.Name;
			methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + Operation.Name),method);
			methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + Operation.Name),method);

			method.ReturnType = new CodeTypeReference (typeof(void));
			methodEnd.ReturnType = new CodeTypeReference (typeof(void));
			methodEnd.Parameters.Add (new CodeParameterDeclarationExpression (typeof (IAsyncResult),varAsyncResult));

			CodeExpression[] paramArray = new CodeExpression [inputMembers.Count];

			for (int n=0; n<inputMembers.Count; n++)
			{
				string ptype = GetSimpleType (inputMembers[n]);
				CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (ptype, inputMembers[n].MemberName);
				
				param.Direction = FieldDirection.In;
				method.Parameters.Add (param);
				methodBegin.Parameters.Add (param);
				paramArray [n] = new CodeVariableReferenceExpression (param.Name);
			}

			bool isVoid = true;
			if (outputMember != null)
			{
				method.ReturnType = new CodeTypeReference (outputMember.TypeFullName);
				methodEnd.ReturnType = new CodeTypeReference (outputMember.TypeFullName);
				xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, outputMember, "");
				isVoid = false;
			}

			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
			methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));

			// Array of input parameters
			
			CodeArrayCreateExpression methodParams;
			if (paramArray.Length > 0)
				methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
			else
				methodParams = new CodeArrayCreateExpression (typeof(object), 0);

			// Generate method url
			
			CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
			
			CodeExpression thisURlExp = new CodeFieldReferenceExpression (ethis, "Url");
			CodePrimitiveExpression metUrl = new CodePrimitiveExpression (httpOper.Location);
			CodeBinaryOperatorExpression expMethodLocation = new CodeBinaryOperatorExpression (thisURlExp, CodeBinaryOperatorType.Add, metUrl);
			
			// Invoke call
			
			CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
			CodeMethodInvokeExpression inv;

			inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, expMethodLocation, methodParams);
			if (!isVoid)
				method.Statements.Add (new CodeMethodReturnStatement (new CodeCastExpression (method.ReturnType, inv)));
			else
				method.Statements.Add (inv);
			
			// Begin Invoke Call
			
			CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
			CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState);
			inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, expMethodLocation, methodParams, expCallb, expAsyncs);
			methodBegin.Statements.Add (new CodeMethodReturnStatement (inv));
			
			// End Invoke call
			
			CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult);
			inv = new CodeMethodInvokeExpression (ethis, "EndInvoke", varAsyncr);
			if (!isVoid)
				methodEnd.Statements.Add (new CodeMethodReturnStatement (new CodeCastExpression (methodEnd.ReturnType, inv)));
			else
				methodEnd.Statements.Add (inv);
			
			// Attributes

			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.HttpMethodAttribute");
			att.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(GetOutMimeFormatter ())));
			att.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(GetInMimeFormatter ())));
			AddCustomAttribute (method, att, true);
		
			CodeTypeDeclaration.Members.Add (method);
			CodeTypeDeclaration.Members.Add (methodBegin);
			CodeTypeDeclaration.Members.Add (methodEnd);
			
			return method;
		}		
Example #50
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;
		}
 string GenerateTypeElement(XmlTypeMapping xmlTypeMapping) {
     ElementAccessor element = xmlTypeMapping.Accessor;
     TypeMapping mapping = element.Mapping;
     string methodName = NextMethodName(element.Name);
     Writer.WriteLine();
     Writer.Write("public object ");
     Writer.Write(methodName);
     Writer.WriteLine("() {");
     Writer.Indent++;
     Writer.WriteLine("object o = null;");
     MemberMapping member = new MemberMapping();
     member.TypeDesc = mapping.TypeDesc;
     //member.ReadOnly = !mapping.TypeDesc.HasDefaultConstructor;
     member.Elements = new ElementAccessor[] { element };
     Member[] members = new Member[] { new Member(this,"o", "o", "a", 0, member) };
     Writer.WriteLine("Reader.MoveToContent();");
     string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");";
     WriteMemberElements(members, "throw CreateUnknownNodeException();", unknownNode, element.Any ? members[0] : null,  null, null);
     if (element.IsSoap) {
         Writer.WriteLine("Referenced(o);");
         Writer.WriteLine("ReadReferencedElements();");
     }
     Writer.WriteLine("return (object)o;");
     Writer.Indent--;
     Writer.WriteLine("}");
     return methodName;
 }
Example #52
0
		XmlTypeMapping CreateTypeMapping (XmlQualifiedName typeQName, SchemaTypes schemaType, XmlQualifiedName root)
		{
			string typeName = CodeIdentifier.MakeValid (typeQName.Name);
			typeName = typeIdentifiers.AddUnique (typeName, null);

			TypeData typeData = new TypeData (typeName, typeName, typeName, schemaType, null);

			string rootElem;
			string rootNs;
			if (root != null) {
				rootElem = root.Name;
				rootNs = root.Namespace;
			}
			else {
				rootElem = typeQName.Name;
				rootNs = "";
			}
			
			XmlTypeMapping map = new XmlTypeMapping (rootElem, rootNs, typeData, typeQName.Name, typeQName.Namespace);
			map.IncludeInSchema = true;
			RegisterTypeMapping (typeQName, typeData, map);

			return map;
		}
		protected override void GenerateClassInclude (CodeAttributeDeclarationCollection attributes, XmlTypeMapping map)
		{
			CodeAttributeDeclaration iatt = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapInclude");
			iatt.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(map.TypeData.FullTypeName)));
			attributes.Add (iatt);
		}
Example #54
0
		XmlTypeMapping CreateArrayTypeMapping (XmlQualifiedName typeQName, TypeData arrayTypeData)
		{
			XmlTypeMapping map;
			if (encodedFormat) map = new XmlTypeMapping ("Array", XmlSerializer.EncodingNamespace, arrayTypeData, "Array", XmlSerializer.EncodingNamespace);
			else map = new XmlTypeMapping (arrayTypeData.XmlType, typeQName.Namespace, arrayTypeData, arrayTypeData.XmlType, typeQName.Namespace);
			
			map.IncludeInSchema = true;
			RegisterTypeMapping (typeQName, arrayTypeData, map);

			return map;
		}
		public void ExportTypeMapping (XmlTypeMapping xmlTypeMapping)
		{
			codeGenerator.ExportTypeMapping (xmlTypeMapping);
		}
Example #56
0
		TypeData GetElementTypeData (XmlQualifiedName typeQName, XmlSchemaElement elem, XmlQualifiedName root, out XmlTypeMapping map)
		{
			bool sharedAnnType = false;
			map = null;
			
			if (!elem.RefName.IsEmpty) {
				XmlSchemaElement refElem = FindRefElement (elem);
				if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
				root = elem.RefName;
				elem = refElem;
				sharedAnnType = true;
			}

			TypeData td;
			if (!elem.SchemaTypeName.IsEmpty) {
				td = GetTypeData (elem.SchemaTypeName, root, elem.IsNillable);
				map = GetRegisteredTypeMapping (td);
			}
			else if (elem.SchemaType == null) 
				td = TypeTranslator.GetTypeData (typeof(object));
			else 
				td = GetTypeData (elem.SchemaType, typeQName, elem.Name, sharedAnnType, root);
			
			if (map == null && td.IsComplexType)
				map = GetTypeMapping (td);
				
			return td;
		}
 /// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="XmlReflectionImporter.ImportTypeMapping1"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlTypeMapping ImportTypeMapping(Type type, string defaultNamespace) {
     ElementAccessor element = new ElementAccessor();
     element.IsSoap = true;
     element.Mapping = ImportTypeMapping(modelScope.GetTypeModel(type));
     element.Name = element.Mapping.DefaultElementName;
     element.Namespace = element.Mapping.Namespace == null ? defaultNamespace : element.Mapping.Namespace;
     element.Form = XmlSchemaForm.Qualified;
     XmlTypeMapping xmlMapping = new XmlTypeMapping(typeScope, element);
     xmlMapping.SetKeyInternal(XmlMapping.GenerateKey(type, null, defaultNamespace));
     xmlMapping.IsSoap = true;
     xmlMapping.GenerateSerializer = true;
     return xmlMapping;
 }
Example #58
0
		XmlTypeMapping GetTypeMapping (TypeData typeData)
		{
			if (typeData.Type == typeof(object) && !anyTypeImported)
				ImportAllObjectTypes ();
				
			XmlTypeMapping map = GetRegisteredTypeMapping (typeData);
			if (map != null) return map;
			
			if (typeData.IsListType)
			{
				// Create an array map for the type

				XmlTypeMapping itemMap = GetTypeMapping (typeData.ListItemTypeData);
				
				map = new XmlTypeMapping (typeData.XmlType, itemMap.Namespace, typeData, typeData.XmlType, itemMap.Namespace);
				map.IncludeInSchema = true;

				ListMap listMap = new ListMap ();
				listMap.ItemInfo = new XmlTypeMapElementInfoList();
				listMap.ItemInfo.Add (CreateElementInfo (itemMap.Namespace, null, typeData.ListItemTypeData.XmlType, typeData.ListItemTypeData, false, XmlSchemaForm.None, -1));
				map.ObjectMap = listMap;
				
				RegisterTypeMapping (new XmlQualifiedName(map.ElementName, map.Namespace), typeData, map);
				return map;
			}
			else if (typeData.SchemaType == SchemaTypes.Primitive || typeData.Type == typeof(object) || typeof(XmlNode).IsAssignableFrom(typeData.Type))
			{
				return CreateSystemMap (typeData);
			}
			
			throw new InvalidOperationException ("Map for type " + typeData.TypeName + " not found");
		}
        string GenerateTypeElement(XmlTypeMapping xmlTypeMapping) {
            ElementAccessor element = xmlTypeMapping.Accessor;
            TypeMapping mapping = element.Mapping;
            string methodName = NextMethodName(element.Name);
            Writer.WriteLine();
            Writer.Write("public void ");
            Writer.Write(methodName);
            Writer.WriteLine("(object o) {");
            Writer.Indent++;

            Writer.WriteLine("WriteStartDocument();");

            Writer.WriteLine("if (o == null) {");
            Writer.Indent++;
            if (element.IsNullable){
                if(mapping.IsSoap)
                    WriteEncodedNullTag(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
                else
                    WriteLiteralNullTag(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
            }
            else
                WriteEmptyTag(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
            Writer.WriteLine("return;");
            Writer.Indent--;
            Writer.WriteLine("}");

            if (!mapping.IsSoap && !mapping.TypeDesc.IsValueType && !mapping.TypeDesc.Type.IsPrimitive) {
                Writer.WriteLine("TopLevelElement();");
            }

            WriteMember("o", null, new ElementAccessor[] { element }, null, null, mapping.TypeDesc, !element.IsSoap);

            if (mapping.IsSoap) {
                Writer.WriteLine("WriteReferencedElements();");
            }
            Writer.Indent--;
            Writer.WriteLine("}");
            return methodName;
        }
Example #60
0
		void AddObjectDerivedMap (XmlTypeMapping map)
		{
			TypeData typeData = TypeTranslator.GetTypeData (typeof(object));
			XmlTypeMapping omap = GetRegisteredTypeMapping (typeData);
			if (omap == null)
				omap = CreateSystemMap (typeData);
			omap.DerivedTypes.Add (map);
		}