AddMember() public method

public AddMember ( System.Xml.Serialization.XmlTypeMapMember member ) : void
member System.Xml.Serialization.XmlTypeMapMember
return void
Beispiel #1
0
        private XmlTypeMapping ImportClassMapping(TypeData typeData, string defaultNamespace)
        {
            Type type = typeData.Type;

            if (type.IsValueType)
            {
                throw this.CreateStructException(type);
            }
            if (type == typeof(object))
            {
                defaultNamespace = "http://www.w3.org/2001/XMLSchema";
            }
            ReflectionHelper.CheckSerializableType(type, false);
            XmlTypeMapping xmlTypeMapping = this.helper.GetRegisteredClrType(type, this.GetTypeNamespace(typeData, defaultNamespace));

            if (xmlTypeMapping != null)
            {
                return(xmlTypeMapping);
            }
            xmlTypeMapping = this.CreateTypeMapping(typeData, null, defaultNamespace);
            this.helper.RegisterClrType(xmlTypeMapping, type, xmlTypeMapping.Namespace);
            xmlTypeMapping.MultiReferenceType = true;
            ClassMap classMap = new ClassMap();

            xmlTypeMapping.ObjectMap = classMap;
            ICollection reflectionMembers = this.GetReflectionMembers(type);

            foreach (object obj in reflectionMembers)
            {
                XmlReflectionMember xmlReflectionMember = (XmlReflectionMember)obj;
                if (!xmlReflectionMember.SoapAttributes.SoapIgnore)
                {
                    classMap.AddMember(this.CreateMapMember(xmlReflectionMember, defaultNamespace));
                }
            }
            SoapIncludeAttribute[] array = (SoapIncludeAttribute[])type.GetCustomAttributes(typeof(SoapIncludeAttribute), false);
            for (int i = 0; i < array.Length; i++)
            {
                Type type2 = array[i].Type;
                this.ImportTypeMapping(type2);
            }
            if (type == typeof(object) && this.includedTypes != null)
            {
                foreach (object obj2 in this.includedTypes)
                {
                    Type type3 = (Type)obj2;
                    xmlTypeMapping.DerivedTypes.Add(this.ImportTypeMapping(type3));
                }
            }
            if (type.BaseType != null)
            {
                XmlTypeMapping xmlTypeMapping2 = this.ImportClassMapping(type.BaseType, defaultNamespace);
                if (type.BaseType != typeof(object))
                {
                    xmlTypeMapping.BaseMap = xmlTypeMapping2;
                }
                this.RegisterDerivedMap(xmlTypeMapping2, xmlTypeMapping);
            }
            return(xmlTypeMapping);
        }
Beispiel #2
0
		internal XmlMembersMapping (string elementName, string ns, bool hasWrapperElement, bool writeAccessors, XmlMemberMapping[] mapping)
		: base (elementName, ns)
		{
			_hasWrapperElement = hasWrapperElement;
			_mapping = mapping;

			ClassMap map = new ClassMap ();
			map.IgnoreMemberNamespace = writeAccessors;
			foreach (XmlMemberMapping mm in mapping)
				map.AddMember (mm.TypeMapMember);
			ObjectMap = map;
		}
        internal XmlMembersMapping(string elementName, string ns, bool hasWrapperElement, bool writeAccessors, XmlMemberMapping[] mapping) : base(elementName, ns)
        {
            this._hasWrapperElement = hasWrapperElement;
            this._mapping           = mapping;
            ClassMap classMap = new ClassMap();

            classMap.IgnoreMemberNamespace = writeAccessors;
            foreach (XmlMemberMapping xmlMemberMapping in mapping)
            {
                classMap.AddMember(xmlMemberMapping.TypeMapMember);
            }
            base.ObjectMap = classMap;
        }
        internal XmlMembersMapping(string elementName, string ns, bool hasWrapperElement, bool writeAccessors, XmlMemberMapping[] mapping)
            : base(elementName, ns)
        {
            _hasWrapperElement = hasWrapperElement;
            _mapping           = mapping;

            ClassMap map = new ClassMap();

            map.IgnoreMemberNamespace = writeAccessors;
            foreach (XmlMemberMapping mm in mapping)
            {
                map.AddMember(mm.TypeMapMember);
            }
            ObjectMap = map;
        }
		XmlTypeMapping ImportClassMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace)
		{
			Type type = typeData.Type;

			XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, root, defaultNamespace));
			if (map != null) return map;

			if (!allowPrivateTypes)
				ReflectionHelper.CheckSerializableType (type, false);
			
			map = CreateTypeMapping (typeData, root, null, defaultNamespace);
			helper.RegisterClrType (map, type, map.XmlTypeNamespace);
			helper.RegisterSchemaType (map, map.XmlType, map.XmlTypeNamespace);

			// Import members

			ClassMap classMap = new ClassMap ();
			map.ObjectMap = classMap;

			ICollection members = GetReflectionMembers (type);
			foreach (XmlReflectionMember rmember in members)
			{
				string ns = map.XmlTypeNamespace;
				if (rmember.XmlAttributes.XmlIgnore) continue;
				if (rmember.DeclaringType != null && rmember.DeclaringType != type) {
					XmlTypeMapping bmap = ImportClassMapping (rmember.DeclaringType, root, defaultNamespace);
					ns = bmap.XmlTypeNamespace;
				}

				try {
					XmlTypeMapMember mem = CreateMapMember (type, rmember, ns);
					mem.CheckOptionalValueType (type);
					classMap.AddMember (mem);
				} catch (Exception ex) {
					throw new InvalidOperationException (string.Format (
						CultureInfo.InvariantCulture, "There was an error" +
						" reflecting field '{0}'.", rmember.MemberName), ex);
				}
			}

			// Import extra classes

			if (type == typeof (object) && includedTypes != null)
			{
				foreach (Type intype in includedTypes)
					map.DerivedTypes.Add (ImportTypeMapping (intype, defaultNamespace));
			}

			// Register inheritance relations

			if (type.BaseType != null)
			{
				XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace);
				ClassMap cbmap = bmap.ObjectMap as ClassMap;
				
				if (type.BaseType != typeof (object)) {
					map.BaseMap = bmap;
					if (!cbmap.HasSimpleContent)
						classMap.SetCanBeSimpleType (false);
				}
				
				// At this point, derived classes of this map must be already registered
				
				RegisterDerivedMap (bmap, map);
				
				if (cbmap.HasSimpleContent && classMap.ElementMembers != null && classMap.ElementMembers.Count != 1)
					throw new InvalidOperationException (String.Format (errSimple, map.TypeData.TypeName, map.BaseMap.TypeData.TypeName));
			}
			
			ImportIncludedTypes (type, defaultNamespace);
			
			if (classMap.XmlTextCollector != null && !classMap.HasSimpleContent)
			{
				XmlTypeMapMember mem = classMap.XmlTextCollector;
				if (mem.TypeData.Type != typeof(string) && 
				   mem.TypeData.Type != typeof(string[]) && 
#if !MOONLIGHT
				   mem.TypeData.Type != typeof(XmlNode[]) && 
#endif
				   mem.TypeData.Type != typeof(object[]))
				   
					throw new InvalidOperationException (String.Format (errSimple2, map.TypeData.TypeName, mem.Name, mem.TypeData.TypeName));
			}
			
			return map;
		}
Beispiel #6
0
		void ImportSequenceContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaObjectCollection items, CodeIdentifiers classIds, bool multiValue, ref bool isMixed)
		{
			foreach (XmlSchemaObject item in items)
			{
				if (item is XmlSchemaElement)
				{
					string ns;
					XmlSchemaElement elem = (XmlSchemaElement) item;
					XmlTypeMapping emap;
					TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);
					XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);

					if (elem.MaxOccurs == 1 && !multiValue)
					{
						XmlTypeMapMemberElement member = null;
						if (typeData.SchemaType != SchemaTypes.Array)
						{
							member = new XmlTypeMapMemberElement ();
							if (refElem.DefaultValue != null) member.DefaultValue = ImportDefaultValue (typeData, refElem.DefaultValue);
						}
						else if (GetTypeMapping (typeData).IsSimpleType)
						{
							// It is a simple list (space separated list).
							// Since this is not supported, map as a single item value
							member = new XmlTypeMapMemberElement ();
#if NET_2_0
							// In MS.NET those types are mapped to a string
							typeData = TypeTranslator.GetTypeData(typeof(string));
#else
							typeData = typeData.ListItemTypeData;
#endif
						}
						else
							member = new XmlTypeMapMemberList ();

						if (elem.MinOccurs == 0 && typeData.IsValueType)
							member.IsOptionalValueType = true;

						member.Name = classIds.AddUnique(CodeIdentifier.MakeValid(refElem.Name), member);
						member.Documentation = GetDocumentation (elem);
						member.TypeData = typeData;
						member.ElementInfo.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable, refElem.Form, emap, items.IndexOf (item)));
						cmap.AddMember (member);
					}
					else
					{
						XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
						member.ListMap = new ListMap ();
						member.Name = classIds.AddUnique(CodeIdentifier.MakeValid(refElem.Name), member);
						member.Documentation = GetDocumentation (elem);
						member.TypeData = typeData.ListTypeData;
						member.ElementInfo.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable, refElem.Form, emap, items.IndexOf (item)));
						member.ListMap.ItemInfo = member.ElementInfo;
						cmap.AddMember (member);
					}
				}
				else if (item is XmlSchemaAny)
				{
					XmlSchemaAny elem = (XmlSchemaAny) item;
					XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement ();
					member.Name = classIds.AddUnique ("Any", member);
					member.Documentation = GetDocumentation (elem);
					
					Type ctype;
					if (elem.MaxOccurs != 1 || multiValue)
						ctype = isMixed ? typeof(XmlNode[]) : typeof(XmlElement[]);
					else
						ctype = isMixed ? typeof(XmlNode) : typeof(XmlElement);

					member.TypeData = TypeTranslator.GetTypeData (ctype);
					XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, member.TypeData);
					einfo.IsUnnamedAnyElement = true;
					member.ElementInfo.Add (einfo);

					if (isMixed)
					{
						einfo = CreateTextElementInfo (typeQName.Namespace, member, member.TypeData);
						member.ElementInfo.Add (einfo);
						member.IsXmlTextCollector = true;
						isMixed = false;	//Allow only one XmlTextAttribute
					}
					
					cmap.AddMember (member);
				}
				else if (item is XmlSchemaParticle) {
					ImportParticleContent (typeQName, cmap, (XmlSchemaParticle)item, classIds, multiValue, ref isMixed);
				}
			}
		}
Beispiel #7
0
		void AddTextMember (XmlQualifiedName typeQName, ClassMap cmap, CodeIdentifiers classIds)
		{
			if (cmap.XmlTextCollector == null)
			{
				XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
				member.Name = classIds.AddUnique ("Text", member);
				member.TypeData = TypeTranslator.GetTypeData (typeof(string[]));
				member.ElementInfo.Add (CreateTextElementInfo (typeQName.Namespace, member, member.TypeData.ListItemTypeData));
				member.IsXmlTextCollector = true;
				member.ListMap = new ListMap ();
				member.ListMap.ItemInfo = member.ElementInfo;
				cmap.AddMember (member);
			}
		}
Beispiel #8
0
		void ImportAttributes (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat, CodeIdentifiers classIds)
		{
			atts = CollectAttributeUsesNonOverlap (atts, cmap);

			if (anyat != null)
			{
    			XmlTypeMapMemberAnyAttribute member = new XmlTypeMapMemberAnyAttribute ();
				member.Name = classIds.AddUnique ("AnyAttribute", member);
				member.TypeData = TypeTranslator.GetTypeData (typeof(XmlAttribute[]));
				cmap.AddMember (member);
			}
			
			foreach (XmlSchemaObject at in atts)
			{
				if (at is XmlSchemaAttribute)
				{
					string ns;
					XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
					XmlSchemaAttribute refAttr = GetRefAttribute (typeQName, attr, out ns);
					XmlTypeMapMemberAttribute member = new XmlTypeMapMemberAttribute ();
					member.Name = classIds.AddUnique (CodeIdentifier.MakeValid (refAttr.Name), member);
					member.Documentation = GetDocumentation (attr);
					member.AttributeName = refAttr.Name;
					member.Namespace = ns;
					member.Form = refAttr.Form;
					member.TypeData = GetAttributeTypeData (typeQName, attr);
					
					if (refAttr.DefaultValue != null) 
						member.DefaultValue = ImportDefaultValue (member.TypeData, refAttr.DefaultValue);
					else if (member.TypeData.IsValueType)
						member.IsOptionalValueType = (refAttr.ValidatedUse != XmlSchemaUse.Required);
						
					if (member.TypeData.IsComplexType)
						member.MappedType = GetTypeMapping (member.TypeData);
					cmap.AddMember (member);
				}
				else if (at is XmlSchemaAttributeGroupRef)
				{
					XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
					XmlSchemaAttributeGroup grp = FindRefAttributeGroup (gref.RefName);
					ImportAttributes (typeQName, cmap, grp.Attributes, grp.AnyAttribute, classIds);
				}
			}
		}
Beispiel #9
0
		void ImportChoiceContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaChoice choice, CodeIdentifiers classIds, bool multiValue)
		{
			XmlTypeMapElementInfoList choices = new XmlTypeMapElementInfoList ();
			multiValue = ImportChoices (typeQName, null, choices, choice.Items) || multiValue;
			if (choices.Count == 0) return;

			if (choice.MaxOccurs > 1) multiValue = true;

			XmlTypeMapMemberElement member;
			if (multiValue)
			{
				member = new XmlTypeMapMemberFlatList ();
				member.Name = classIds.AddUnique ("Items", member);
				ListMap listMap = new ListMap ();
				listMap.ItemInfo = choices;
				((XmlTypeMapMemberFlatList)member).ListMap = listMap;
			}
			else
			{
				member = new XmlTypeMapMemberElement ();
				member.Name = classIds.AddUnique ("Item", member);
			}
			
			// If all choices have the same type, use that type for the member.
			// If not use System.Object.
			// If there are at least two choices with the same type, use a choice
			// identifier attribute

			TypeData typeData = null;
			bool twoEqual = false;
			bool allEqual = true;
			Hashtable types = new Hashtable ();

			for (int n = choices.Count - 1; n >= 0; n--)
			{
				XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) choices [n];
				
				// In some complex schemas, we may end up with several options
				// with the same name. It is better to ignore the extra options
				// than to crash. It's the best we can do, and btw it works
				// better than in MS.NET.
				
				if (cmap.GetElement (einfo.ElementName, einfo.Namespace, einfo.ExplicitOrder) != null ||
					choices.IndexOfElement (einfo.ElementName, einfo.Namespace) != n)
				{
					choices.RemoveAt (n);
					continue;
				}
					
				if (types.ContainsKey (einfo.TypeData)) twoEqual = true;
				else types.Add (einfo.TypeData, einfo);

				TypeData choiceType = einfo.TypeData;
				if (choiceType.SchemaType == SchemaTypes.Class)
				{
					// When comparing class types, use the most generic class in the
					// inheritance hierarchy

					XmlTypeMapping choiceMap = GetTypeMapping (choiceType);
					BuildPendingMap (choiceMap);
					while (choiceMap.BaseMap != null) {
						choiceMap = choiceMap.BaseMap;
						BuildPendingMap (choiceMap);
						choiceType = choiceMap.TypeData;
					}
				}
				
				if (typeData == null) typeData = choiceType;
				else if (typeData != choiceType) allEqual = false;
			}

			if (!allEqual)
				typeData = TypeTranslator.GetTypeData (typeof(object));

			if (twoEqual)
			{
				// Create the choice member
				XmlTypeMapMemberElement choiceMember = new XmlTypeMapMemberElement ();
				choiceMember.Ignore = true;
				choiceMember.Name = classIds.AddUnique (member.Name + "ElementName", choiceMember);
				member.ChoiceMember = choiceMember.Name;

				// Create the choice enum
				XmlTypeMapping enumMap = CreateTypeMapping (new XmlQualifiedName (member.Name + "ChoiceType", typeQName.Namespace), SchemaTypes.Enum, null);
				enumMap.IncludeInSchema = false;

				CodeIdentifiers codeIdents = new CodeIdentifiers ();
				EnumMap.EnumMapMember[] members = new EnumMap.EnumMapMember [choices.Count];
				for (int n=0; n<choices.Count; n++)
				{
					XmlTypeMapElementInfo it =(XmlTypeMapElementInfo) choices[n];
					bool extraNs = (it.Namespace != null && it.Namespace != "" && it.Namespace != typeQName.Namespace);
					string xmlName = extraNs ? it.Namespace + ":" + it.ElementName : it.ElementName;
					string enumName = codeIdents.AddUnique (CodeIdentifier.MakeValid (it.ElementName), it);
					members [n] = new EnumMap.EnumMapMember (xmlName, enumName);
				}
				enumMap.ObjectMap = new EnumMap (members, false);

				choiceMember.TypeData = multiValue ? enumMap.TypeData.ListTypeData : enumMap.TypeData;
				choiceMember.ElementInfo.Add (CreateElementInfo (typeQName.Namespace, choiceMember, choiceMember.Name, choiceMember.TypeData, false, XmlSchemaForm.None, -1));
				cmap.AddMember (choiceMember);
			}
			
			if (typeData == null)
				return;
	
			if (multiValue)
				typeData = typeData.ListTypeData;

			member.ElementInfo = choices;
			member.Documentation = GetDocumentation (choice);
			member.TypeData = typeData;
			cmap.AddMember (member);
		}
Beispiel #10
0
		XmlTypeMapping ImportClassMapping (TypeData typeData, string defaultNamespace)
		{
			Type type = typeData.Type;

			if (type.IsValueType) throw CreateStructException (type);

			if (type == typeof (object)) defaultNamespace = XmlSchema.Namespace;

			ReflectionHelper.CheckSerializableType (type, false);
			XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, defaultNamespace));
			if (map != null) return map;

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

			ClassMap classMap = new ClassMap ();
			map.ObjectMap = classMap;

			// Import members

			ICollection members = GetReflectionMembers (type);
			foreach (XmlReflectionMember rmember in members) {
				if (rmember.SoapAttributes.SoapIgnore) continue;
				classMap.AddMember (CreateMapMember (rmember, defaultNamespace));
			}

			// Import included classes

			SoapIncludeAttribute[] includes = (SoapIncludeAttribute[])type.GetCustomAttributes (typeof (SoapIncludeAttribute), false);
			for (int n=0; n<includes.Length; n++)
			{
				Type includedType = includes[n].Type;
				ImportTypeMapping (includedType);
			}

			if (type == typeof (object) && includedTypes != null)
			{
				foreach (Type intype in includedTypes)
					map.DerivedTypes.Add (ImportTypeMapping (intype));
			}

			// Register inheritance relations

			if (type.BaseType != null)
			{
				XmlTypeMapping bmap = ImportClassMapping (type.BaseType, defaultNamespace);
				
				if (type.BaseType != typeof (object))
					map.BaseMap = bmap;
					
				// At this point, derived classes of this map must be already registered
				
				RegisterDerivedMap (bmap, map);
			}
			
			return map;
		}
Beispiel #11
0
		XmlTypeMapping ImportClassMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace)
		{
			Type type = typeData.Type;

			XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, root, defaultNamespace));
			if (map != null) return map;

			if (!allowPrivateTypes)
				ReflectionHelper.CheckSerializableType (type, false);
			
			map = CreateTypeMapping (typeData, root, null, defaultNamespace);
			helper.RegisterClrType (map, type, map.XmlTypeNamespace);
			helper.RegisterSchemaType (map, map.XmlType, map.XmlTypeNamespace);

			// Import members

			ClassMap classMap = new ClassMap ();
			map.ObjectMap = classMap;

			var members = GetReflectionMembers (type);
			bool? isOrderExplicit = null;
			foreach (XmlReflectionMember rmember in members)
			{
				int? order = rmember.XmlAttributes.Order;
				if (isOrderExplicit == null)
				{
					if (order != null)
						isOrderExplicit = (int) order >= 0;
				}
				else if (order != null && isOrderExplicit != ((int) order >= 0))
					throw new InvalidOperationException ("Inconsistent XML sequence was detected. If there are XmlElement/XmlArray/XmlAnyElement attributes with explicit Order, then every other member must have an explicit order too.");
			}
			if (isOrderExplicit == true)
				members.Sort ((m1, m2) => (int) m1.XmlAttributes.SortableOrder - (int) m2.XmlAttributes.SortableOrder);

			foreach (XmlReflectionMember rmember in members)
			{
				string ns = map.XmlTypeNamespace;
				if (rmember.XmlAttributes.XmlIgnore) continue;
				if (rmember.DeclaringType != null && rmember.DeclaringType != type) {
					XmlTypeMapping bmap = ImportClassMapping (rmember.DeclaringType, root, defaultNamespace);
					if (bmap.HasXmlTypeNamespace)
						ns = bmap.XmlTypeNamespace;
				}

				try {
					XmlTypeMapMember mem = CreateMapMember (type, rmember, ns);
					mem.CheckOptionalValueType (type);
					classMap.AddMember (mem);
				} catch (Exception ex) {
					throw new InvalidOperationException (string.Format (
						CultureInfo.InvariantCulture, "There was an error" +
						" reflecting field '{0}'.", rmember.MemberName), ex);
				}
			}

			// Import extra classes

			if (type == typeof (object) && includedTypes != null)
			{
				foreach (Type intype in includedTypes)
					map.DerivedTypes.Add (ImportTypeMapping (intype, defaultNamespace));
			}

			// Register inheritance relations

			if (type.BaseType != null)
			{
				XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace);
				ClassMap cbmap = bmap.ObjectMap as ClassMap;
				
				if (type.BaseType != typeof (object)) {
					map.BaseMap = bmap;
					if (!cbmap.HasSimpleContent)
						classMap.SetCanBeSimpleType (false);
				}
				
				// At this point, derived classes of this map must be already registered
				
				RegisterDerivedMap (bmap, map);
				
				if (cbmap.HasSimpleContent && classMap.ElementMembers != null && classMap.ElementMembers.Count != 1)
					throw new InvalidOperationException (String.Format (errSimple, map.TypeData.TypeName, map.BaseMap.TypeData.TypeName));
			}
			
			ImportIncludedTypes (type, defaultNamespace);
			
			if (classMap.XmlTextCollector != null && !classMap.HasSimpleContent)
			{
				XmlTypeMapMember mem = classMap.XmlTextCollector;
				if (mem.TypeData.Type != typeof(string) && 
				   mem.TypeData.Type != typeof(string[]) && 
				   mem.TypeData.Type != typeof(XmlNode[]) && 
				   mem.TypeData.Type != typeof(object[]))
				   
					throw new InvalidOperationException (String.Format (errSimple2, map.TypeData.TypeName, mem.Name, mem.TypeData.TypeName));
			}
			
			return map;
		}
Beispiel #12
0
        XmlTypeMapping ImportClassMapping(Type type, XmlRootAttribute root, string defaultNamespace)
        {
            TypeData       typeData = TypeTranslator.GetTypeData(type);
            XmlTypeMapping map      = helper.GetRegisteredClrType(type, GetTypeNamespace(typeData, root, defaultNamespace));

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

            if (!allowPrivateTypes)
            {
                ReflectionHelper.CheckSerializableType(type);
            }

            map = CreateTypeMapping(typeData, root, null, defaultNamespace);
            helper.RegisterClrType(map, type, map.XmlTypeNamespace);
            helper.RegisterSchemaType(map, map.XmlType, map.XmlTypeNamespace);

            // Import members

            ClassMap classMap = new ClassMap();

            map.ObjectMap = classMap;

//			try
//			{
            ICollection members = GetReflectionMembers(type);

            foreach (XmlReflectionMember rmember in members)
            {
                if (rmember.XmlAttributes.XmlIgnore)
                {
                    continue;
                }
                XmlTypeMapMember mem = CreateMapMember(rmember, map.XmlTypeNamespace);
                mem.CheckOptionalValueType(type);
                classMap.AddMember(mem);
            }
//			}
//			catch (Exception ex) {
//				throw helper.CreateError (map, ex.Message);
//			}

            ImportIncludedTypes(type, defaultNamespace);

            // Import extra classes

            if (type == typeof(object) && includedTypes != null)
            {
                foreach (Type intype in includedTypes)
                {
                    map.DerivedTypes.Add(ImportTypeMapping(intype, defaultNamespace));
                }
            }

            // Register inheritance relations

            if (type.BaseType != null)
            {
                XmlTypeMapping bmap = ImportClassMapping(type.BaseType, root, defaultNamespace);

                if (type.BaseType != typeof(object))
                {
                    map.BaseMap = bmap;
                    classMap.SetCanBeSimpleType(false);
                }

                // At this point, derived classes of this map must be already registered

                RegisterDerivedMap(bmap, map);

                if (((ClassMap)bmap.ObjectMap).HasSimpleContent && classMap.ElementMembers != null && classMap.ElementMembers.Count != 1)
                {
                    throw new InvalidOperationException(String.Format(errSimple, map.TypeData.TypeName, map.BaseMap.TypeData.TypeName));
                }
            }

            if (classMap.XmlTextCollector != null && !classMap.HasSimpleContent)
            {
                XmlTypeMapMember mem = classMap.XmlTextCollector;
                if (mem.TypeData.Type != typeof(string) &&
                    mem.TypeData.Type != typeof(string[]) &&
                    mem.TypeData.Type != typeof(object[]) &&
                    mem.TypeData.Type != typeof(XmlNode[]))
                {
                    throw new InvalidOperationException(String.Format(errSimple2, map.TypeData.TypeName, mem.Name, mem.TypeData.TypeName));
                }
            }

            return(map);
        }
		void ImportParticleComplexContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaParticle particle, CodeIdentifiers classIds, bool isMixed)
		{
			ImportParticleContent (typeQName, cmap, particle, classIds, false, ref isMixed);
			if (isMixed && cmap.XmlTextCollector == null)
			{
				XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
				member.Name = classIds.AddUnique ("Text", member);
				member.TypeData = TypeTranslator.GetTypeData (typeof(string[]));
				member.ElementInfo.Add (CreateTextElementInfo (typeQName.Namespace, member, member.TypeData.ListItemTypeData));
				member.IsXmlTextCollector = true;
				member.ListMap = new ListMap ();
				member.ListMap.ItemInfo = member.ElementInfo;
				cmap.AddMember (member);
			}
		}
        XmlTypeMapping ImportClassMapping(TypeData typeData, string defaultNamespace)
        {
            Type type = typeData.Type;

            if (type.IsValueType)
            {
                throw CreateStructException(type);
            }

            if (type == typeof(object))
            {
                defaultNamespace = XmlSchema.Namespace;
            }

            ReflectionHelper.CheckSerializableType(type, false);
            XmlTypeMapping map = helper.GetRegisteredClrType(type, GetTypeNamespace(typeData, defaultNamespace));

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

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

            ClassMap classMap = new ClassMap();

            map.ObjectMap = classMap;

            // Import members

            ICollection members = GetReflectionMembers(type);

            foreach (XmlReflectionMember rmember in members)
            {
                if (rmember.SoapAttributes.SoapIgnore)
                {
                    continue;
                }
                classMap.AddMember(CreateMapMember(rmember, defaultNamespace));
            }

            // Import included classes

            SoapIncludeAttribute[] includes = (SoapIncludeAttribute[])type.GetCustomAttributes(typeof(SoapIncludeAttribute), false);
            for (int n = 0; n < includes.Length; n++)
            {
                Type includedType = includes[n].Type;
                ImportTypeMapping(includedType);
            }

            if (type == typeof(object) && includedTypes != null)
            {
                foreach (Type intype in includedTypes)
                {
                    map.DerivedTypes.Add(ImportTypeMapping(intype));
                }
            }

            // Register inheritance relations

            if (type.BaseType != null)
            {
                XmlTypeMapping bmap = ImportClassMapping(type.BaseType, defaultNamespace);

                if (type.BaseType != typeof(object))
                {
                    map.BaseMap = bmap;
                }

                // At this point, derived classes of this map must be already registered

                RegisterDerivedMap(bmap, map);
            }

            return(map);
        }
		XmlTypeMapping ImportClassMapping (Type type, XmlRootAttribute root, string defaultNamespace)
		{
			TypeData typeData = TypeTranslator.GetTypeData (type);
			XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, root, defaultNamespace));
			if (map != null) return map;

			if (!allowPrivateTypes)
				ReflectionHelper.CheckSerializableType (type);
			
			map = CreateTypeMapping (typeData, root, null, defaultNamespace);
			helper.RegisterClrType (map, type, map.XmlTypeNamespace);
			helper.RegisterSchemaType (map, map.XmlType, map.XmlTypeNamespace);

			// Import members

			ClassMap classMap = new ClassMap ();
			map.ObjectMap = classMap;

//			try
//			{
				ICollection members = GetReflectionMembers (type);
				foreach (XmlReflectionMember rmember in members)
				{
					if (rmember.XmlAttributes.XmlIgnore) continue;
					XmlTypeMapMember mem = CreateMapMember (rmember, map.XmlTypeNamespace);
					mem.CheckOptionalValueType (type);
					classMap.AddMember (mem);
				}
//			}
//			catch (Exception ex) {
//				throw helper.CreateError (map, ex.Message);
//			}

			ImportIncludedTypes (type, defaultNamespace);
			
			// Import extra classes

			if (type == typeof (object) && includedTypes != null)
			{
				foreach (Type intype in includedTypes)
					map.DerivedTypes.Add (ImportTypeMapping (intype, defaultNamespace));
			}

			// Register inheritance relations

			if (type.BaseType != null)
			{
				XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace);
				
				if (type.BaseType != typeof (object)) {
					map.BaseMap = bmap;
					classMap.SetCanBeSimpleType (false);
				}
				
				// At this point, derived classes of this map must be already registered
				
				RegisterDerivedMap (bmap, map);
				
				if (((ClassMap)bmap.ObjectMap).HasSimpleContent && classMap.ElementMembers != null && classMap.ElementMembers.Count != 1)
					throw new InvalidOperationException (String.Format (errSimple, map.TypeData.TypeName, map.BaseMap.TypeData.TypeName));
			}
			
			if (classMap.XmlTextCollector != null && !classMap.HasSimpleContent)
			{
				XmlTypeMapMember mem = classMap.XmlTextCollector;
				if (mem.TypeData.Type != typeof(string) && 
				   mem.TypeData.Type != typeof(string[]) && 
				   mem.TypeData.Type != typeof(object[]) && 
				   mem.TypeData.Type != typeof(XmlNode[]))
				   
					throw new InvalidOperationException (String.Format (errSimple2, map.TypeData.TypeName, mem.Name, mem.TypeData.TypeName));
			}
			
			return map;
		}