private XmlTypeMapMember CreateMapMember (Type declaringType, XmlReflectionMember rmember, string defaultNamespace)
		{
			XmlTypeMapMember mapMember;
			XmlAttributes atts = rmember.XmlAttributes;
			TypeData typeData = TypeTranslator.GetTypeData (rmember.MemberType);

			if (atts.XmlArray != null) {
				if (atts.XmlArray.Namespace != null && atts.XmlArray.Form == XmlSchemaForm.Unqualified)
					throw new InvalidOperationException ("XmlArrayAttribute.Form must not be Unqualified when it has an explicit Namespace value.");
				if (typeData.SchemaType != SchemaTypes.Array &&
				    !(typeData.SchemaType == SchemaTypes.Primitive && typeData.Type == typeof (byte [])))
					throw new InvalidOperationException ("XmlArrayAttribute can be applied to members of array or collection type.");
			}

#if !MOONLIGHT
			if (atts.XmlAnyAttribute != null)
			{
				if ( (rmember.MemberType.FullName == "System.Xml.XmlAttribute[]") ||
					 (rmember.MemberType.FullName == "System.Xml.XmlNode[]") )
				{
					mapMember = new XmlTypeMapMemberAnyAttribute();
				}
				else
					throw new InvalidOperationException ("XmlAnyAttributeAttribute can only be applied to members of type XmlAttribute[] or XmlNode[]");
			}
			else
#endif
			if (atts.XmlAnyElements != null && atts.XmlAnyElements.Count > 0)
			{
				// no XmlNode type check is done here (seealso: bug #553032).
				XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement();
				member.ElementInfo = ImportAnyElementInfo (defaultNamespace, rmember, member, atts);
				mapMember = member;
			}
			else if (atts.Xmlns)
			{
				XmlTypeMapMemberNamespaces mapNamespaces = new XmlTypeMapMemberNamespaces ();
				mapMember = mapNamespaces;
			}
			else if (atts.XmlAttribute != null)
			{
				// An attribute

				if (atts.XmlElements != null && atts.XmlElements.Count > 0)
					throw new Exception ("XmlAttributeAttribute and XmlElementAttribute cannot be applied to the same member");

				XmlTypeMapMemberAttribute mapAttribute = new XmlTypeMapMemberAttribute ();
				if (atts.XmlAttribute.AttributeName.Length == 0) 
					mapAttribute.AttributeName = rmember.MemberName;
				else 
					mapAttribute.AttributeName = atts.XmlAttribute.AttributeName;

				mapAttribute.AttributeName = XmlConvert.EncodeLocalName (mapAttribute.AttributeName);

				if (typeData.IsComplexType)
					mapAttribute.MappedType = ImportTypeMapping (typeData.Type, null, defaultNamespace);

				if (atts.XmlAttribute.Namespace != null && atts.XmlAttribute.Namespace != defaultNamespace)
				{
					if (atts.XmlAttribute.Form == XmlSchemaForm.Unqualified)
						throw new InvalidOperationException ("The Form property may not be 'Unqualified' when an explicit Namespace property is present");
					mapAttribute.Form = XmlSchemaForm.Qualified;
					mapAttribute.Namespace = atts.XmlAttribute.Namespace;
				}
				else
				{
					mapAttribute.Form = atts.XmlAttribute.Form;
					if (atts.XmlAttribute.Form == XmlSchemaForm.Qualified)
						mapAttribute.Namespace = defaultNamespace;
					else
						mapAttribute.Namespace = "";
				}
				
				typeData = TypeTranslator.GetTypeData(rmember.MemberType, atts.XmlAttribute.DataType);
				mapMember = mapAttribute;
			}
			else if (typeData.SchemaType == SchemaTypes.Array)
			{
				// If the member has a single XmlElementAttribute and the type is the type of the member,
				// then it is not a flat list
				
				if (atts.XmlElements.Count > 1 ||
				   (atts.XmlElements.Count == 1 && atts.XmlElements[0].Type != typeData.Type) ||
				   (atts.XmlText != null))
				{
					// A flat list

					// check that it does not have XmlArrayAttribute
					if (atts.XmlArray != null)
						throw new InvalidOperationException ("XmlArrayAttribute cannot be used with members which also attributed with XmlElementAttribute or XmlTextAttribute.");

					XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
					member.ListMap = new ListMap ();
					member.ListMap.ItemInfo = ImportElementInfo (declaringType, XmlConvert.EncodeLocalName (rmember.MemberName), defaultNamespace, typeData.ListItemType, member, atts);
					member.ElementInfo = member.ListMap.ItemInfo;
					member.ListMap.ChoiceMember = member.ChoiceMember;
					mapMember = member;
				}
				else
				{
					// A list

					XmlTypeMapMemberList member = new XmlTypeMapMemberList ();

					// Creates an ElementInfo that identifies the array instance. 
					member.ElementInfo = new XmlTypeMapElementInfoList();
					XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, typeData);
					elem.ElementName = XmlConvert.EncodeLocalName((atts.XmlArray != null && atts.XmlArray.ElementName.Length != 0) ? atts.XmlArray.ElementName : rmember.MemberName);
					// note that it could be changed below (when Form is Unqualified)
					elem.Namespace = (atts.XmlArray != null && atts.XmlArray.Namespace != null) ? atts.XmlArray.Namespace : defaultNamespace;
					elem.MappedType = ImportListMapping (rmember.MemberType, null, elem.Namespace, atts, 0);
					elem.IsNullable = (atts.XmlArray != null) ? atts.XmlArray.IsNullable : false;
					elem.Form = (atts.XmlArray != null) ? atts.XmlArray.Form : XmlSchemaForm.Qualified;
					// This is a bit tricky, but is done
					// after filling descendant members, so
					// that array items could be serialized
					// with proper namespace.
					if (atts.XmlArray != null && atts.XmlArray.Form == XmlSchemaForm.Unqualified)
						elem.Namespace = String.Empty;

					member.ElementInfo.Add (elem);
					mapMember = member;
				}
			}
			else
			{
				// An element

				XmlTypeMapMemberElement member = new XmlTypeMapMemberElement ();
 				member.ElementInfo = ImportElementInfo (declaringType, XmlConvert.EncodeLocalName(rmember.MemberName), defaultNamespace, rmember.MemberType, member, atts);
				mapMember = member;
			}

			mapMember.DefaultValue = GetDefaultValue (typeData, atts.XmlDefaultValue);
			mapMember.TypeData = typeData;
			mapMember.Name = rmember.MemberName;
			mapMember.IsReturnValue = rmember.IsReturnValue;
			return mapMember;
		}
        public void AddMember(XmlTypeMapMember member)
        {
            // If GlobalIndex has not been set, set it now
            if (member.GlobalIndex == -1)
            {
                member.GlobalIndex = _allMembers.Count;
            }

            _allMembers.Add(member);

            if (!(member.DefaultValue is System.DBNull) && member.DefaultValue != null)
            {
                if (_membersWithDefault == null)
                {
                    _membersWithDefault = new ArrayList();
                }
                _membersWithDefault.Add(member);
            }

            if (member.IsReturnValue)
            {
                _returnMember = member;
            }

            if (member is XmlTypeMapMemberAttribute)
            {
                XmlTypeMapMemberAttribute atm = (XmlTypeMapMemberAttribute)member;
                if (_attributeMembers == null)
                {
                    _attributeMembers = new Hashtable();
                }
                string key = BuildKey(atm.AttributeName, atm.Namespace, -1);
                if (_attributeMembers.ContainsKey(key))
                {
                    throw new InvalidOperationException("The XML attribute named '" + atm.AttributeName + "' from namespace '" + atm.Namespace + "' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the attribute.");
                }
                member.Index = _attributeMembers.Count;
                _attributeMembers.Add(key, member);
                return;
            }
            else if (member is XmlTypeMapMemberFlatList)
            {
                RegisterFlatList((XmlTypeMapMemberFlatList)member);
            }
            else if (member is XmlTypeMapMemberAnyElement)
            {
                XmlTypeMapMemberAnyElement mem = (XmlTypeMapMemberAnyElement)member;
                if (mem.IsDefaultAny)
                {
                    _defaultAnyElement = mem;
                }
                if (mem.TypeData.IsListType)
                {
                    RegisterFlatList(mem);
                }
            }
            else if (member is XmlTypeMapMemberAnyAttribute)
            {
                _defaultAnyAttribute = (XmlTypeMapMemberAnyAttribute)member;
                return;
            }
            else if (member is XmlTypeMapMemberNamespaces)
            {
                _namespaceDeclarations = (XmlTypeMapMemberNamespaces)member;
                return;
            }

            if (member is XmlTypeMapMemberElement && ((XmlTypeMapMemberElement)member).IsXmlTextCollector)
            {
                if (_xmlTextCollector != null)
                {
                    throw new InvalidOperationException("XmlTextAttribute can only be applied once in a class");
                }
                _xmlTextCollector = member;
            }

            if (_elementMembers == null)
            {
                _elementMembers = new ArrayList();
                _elements       = new Hashtable();
            }

            member.Index = _elementMembers.Count;
            _elementMembers.Add(member);

            ICollection elemsInfo = ((XmlTypeMapMemberElement)member).ElementInfo;

            foreach (XmlTypeMapElementInfo elem in elemsInfo)
            {
                string key = BuildKey(elem.ElementName, elem.Namespace, elem.ExplicitOrder);
                if (_elements.ContainsKey(key))
                {
                    throw new InvalidOperationException("The XML element named '" + elem.ElementName + "' from namespace '" + elem.Namespace + "' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.");
                }
                _elements.Add(key, elem);
            }

            if (member.TypeData.IsListType && member.TypeData.Type != null && !member.TypeData.Type.IsArray)
            {
                if (_listMembers == null)
                {
                    _listMembers = new ArrayList();
                }
                _listMembers.Add(member);
            }
        }
Example #3
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);
				}
			}
		}
Example #4
0
		public void AddMember (XmlTypeMapMember member)
		{
			// If GlobalIndex has not been set, set it now
			if (member.GlobalIndex == -1)
				member.GlobalIndex = _allMembers.Count;
			
			_allMembers.Add (member);
			
			if (!(member.DefaultValue is System.DBNull) && member.DefaultValue != null) {
				if (_membersWithDefault == null) _membersWithDefault = new ArrayList ();
				_membersWithDefault.Add (member);
			}
			
			if (member.IsReturnValue)
				_returnMember = member;
			
			if (member is XmlTypeMapMemberAttribute)
			{
				XmlTypeMapMemberAttribute atm = (XmlTypeMapMemberAttribute)member;
				if (_attributeMembers == null) _attributeMembers = new Hashtable();
				string key = BuildKey (atm.AttributeName, atm.Namespace, -1);
				if (_attributeMembers.ContainsKey (key))
					throw new InvalidOperationException ("The XML attribute named '" + atm.AttributeName + "' from namespace '" + atm.Namespace + "' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the attribute.");
				member.Index = _attributeMembers.Count;
				_attributeMembers.Add (key, member);
				return;
			}
			else if (member is XmlTypeMapMemberFlatList)
			{
				RegisterFlatList ((XmlTypeMapMemberFlatList)member);
			}
			else if (member is XmlTypeMapMemberAnyElement)
			{
				XmlTypeMapMemberAnyElement mem = (XmlTypeMapMemberAnyElement) member;
				if (mem.IsDefaultAny) _defaultAnyElement = mem;
				if (mem.TypeData.IsListType) RegisterFlatList (mem);
			}
			else if (member is XmlTypeMapMemberAnyAttribute)
			{
				_defaultAnyAttribute = (XmlTypeMapMemberAnyAttribute) member;
				return;
			}
			else if (member is XmlTypeMapMemberNamespaces)
			{
				_namespaceDeclarations = (XmlTypeMapMemberNamespaces) member;
				return;
			}

			if (member is XmlTypeMapMemberElement && ((XmlTypeMapMemberElement)member).IsXmlTextCollector)
			{
				if (_xmlTextCollector != null) throw new InvalidOperationException ("XmlTextAttribute can only be applied once in a class");
				_xmlTextCollector = member;
			}

			if (_elementMembers == null) {
				_elementMembers = new ArrayList();
				_elements = new Hashtable();
			}

			member.Index = _elementMembers.Count;
			_elementMembers.Add (member);

			ICollection elemsInfo = ((XmlTypeMapMemberElement)member).ElementInfo;
			foreach (XmlTypeMapElementInfo elem in elemsInfo)
			{
				string key = BuildKey (elem.ElementName, elem.Namespace, elem.ExplicitOrder);
				if (_elements.ContainsKey (key)) 
					throw new InvalidOperationException ("The XML element named '" + elem.ElementName + "' from namespace '" + elem.Namespace + "' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.");
				_elements.Add (key, elem);
			}
			
			if (member.TypeData.IsListType && member.TypeData.Type != null && !member.TypeData.Type.IsArray) {
				if (_listMembers == null) _listMembers = new ArrayList ();
				_listMembers.Add (member);
			}
		}
Example #5
0
        private XmlTypeMapMember CreateMapMember(XmlReflectionMember rmember, string defaultNamespace)
        {
            XmlTypeMapMember mapMember;
            XmlAttributes    atts     = rmember.XmlAttributes;
            TypeData         typeData = TypeTranslator.GetTypeData(rmember.MemberType);

            if (atts.XmlAnyAttribute != null)
            {
                if ((rmember.MemberType.FullName == "System.Xml.XmlAttribute[]") ||
                    (rmember.MemberType.FullName == "System.Xml.XmlNode[]"))
                {
                    mapMember = new XmlTypeMapMemberAnyAttribute();
                }
                else
                {
                    throw new InvalidOperationException("XmlAnyAttributeAttribute can only be applied to members of type XmlAttribute[] or XmlNode[]");
                }
            }
            else if (atts.XmlAnyElements != null && atts.XmlAnyElements.Count > 0)
            {
                if ((rmember.MemberType.FullName == "System.Xml.XmlElement[]") ||
                    (rmember.MemberType.FullName == "System.Xml.XmlNode[]") ||
                    (rmember.MemberType.FullName == "System.Xml.XmlElement"))
                {
                    XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement();
                    member.ElementInfo = ImportAnyElementInfo(defaultNamespace, rmember, member, atts);
                    mapMember          = member;
                }
                else
                {
                    throw new InvalidOperationException("XmlAnyElementAttribute can only be applied to members of type XmlElement, XmlElement[] or XmlNode[]");
                }
            }
            else if (atts.Xmlns)
            {
                XmlTypeMapMemberNamespaces mapNamespaces = new XmlTypeMapMemberNamespaces();
                mapMember = mapNamespaces;
            }
            else if (atts.XmlAttribute != null)
            {
                // An attribute

                if (atts.XmlElements != null && atts.XmlElements.Count > 0)
                {
                    throw new Exception("XmlAttributeAttribute and XmlElementAttribute cannot be applied to the same member");
                }

                XmlTypeMapMemberAttribute mapAttribute = new XmlTypeMapMemberAttribute();
                if (atts.XmlAttribute.AttributeName == null)
                {
                    mapAttribute.AttributeName = rmember.MemberName;
                }
                else
                {
                    mapAttribute.AttributeName = atts.XmlAttribute.AttributeName;
                }

                if (typeData.IsComplexType)
                {
                    mapAttribute.MappedType = ImportTypeMapping(typeData.Type, null, mapAttribute.Namespace);
                }

                if (atts.XmlAttribute.Namespace != null && atts.XmlAttribute.Namespace != defaultNamespace)
                {
                    if (atts.XmlAttribute.Form == XmlSchemaForm.Unqualified)
                    {
                        throw new InvalidOperationException("The Form property may not be 'Unqualified' when an explicit Namespace property is present");
                    }
                    mapAttribute.Form      = XmlSchemaForm.Qualified;
                    mapAttribute.Namespace = atts.XmlAttribute.Namespace;
                }
                else
                {
                    mapAttribute.Form = atts.XmlAttribute.Form;
                    if (atts.XmlAttribute.Form == XmlSchemaForm.Qualified)
                    {
                        mapAttribute.Namespace = defaultNamespace;
                    }
                    else
                    {
                        mapAttribute.Namespace = "";
                    }
                }

                typeData  = TypeTranslator.GetTypeData(rmember.MemberType, atts.XmlAttribute.DataType);
                mapMember = mapAttribute;
            }
            else if (typeData.SchemaType == SchemaTypes.Array)
            {
                // If the member has a single XmlElementAttribute and the type is the type of the member,
                // then it is not a flat list

                if (atts.XmlElements.Count > 1 ||
                    (atts.XmlElements.Count == 1 && atts.XmlElements[0].Type != typeData.Type) ||
                    (atts.XmlText != null))
                {
                    // A flat list

                    // TODO: check that it does not have XmlArrayAttribute
                    XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList();
                    member.ListMap          = new ListMap();
                    member.ListMap.ItemInfo = ImportElementInfo(rmember.MemberName, defaultNamespace, typeData.ListItemType, member, atts);
                    member.ElementInfo      = member.ListMap.ItemInfo;
                    mapMember = member;
                }
                else
                {
                    // A list

                    XmlTypeMapMemberList member = new XmlTypeMapMemberList();

                    // Creates an ElementInfo that identifies the array instance.
                    member.ElementInfo = new XmlTypeMapElementInfoList();
                    XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo(member, typeData);
                    elem.ElementName = (atts.XmlArray != null && atts.XmlArray.ElementName != null) ? atts.XmlArray.ElementName : rmember.MemberName;
                    elem.Namespace   = (atts.XmlArray != null && atts.XmlArray.Namespace != null) ? atts.XmlArray.Namespace : defaultNamespace;
                    elem.MappedType  = ImportListMapping(rmember.MemberType, null, elem.Namespace, atts, 0);
                    elem.IsNullable  = (atts.XmlArray != null) ? atts.XmlArray.IsNullable : false;
                    elem.Form        = (atts.XmlArray != null) ? atts.XmlArray.Form : XmlSchemaForm.Qualified;

                    member.ElementInfo.Add(elem);
                    mapMember = member;
                }
            }
            else
            {
                // An element

                XmlTypeMapMemberElement member = new XmlTypeMapMemberElement();
                member.ElementInfo = ImportElementInfo(rmember.MemberName, defaultNamespace, rmember.MemberType, member, atts);
                mapMember          = member;
            }

            mapMember.DefaultValue  = atts.XmlDefaultValue;
            mapMember.TypeData      = typeData;
            mapMember.Name          = rmember.MemberName;
            mapMember.IsReturnValue = rmember.IsReturnValue;
            return(mapMember);
        }
Example #6
0
        public void AddMember(XmlTypeMapMember member)
        {
            member.GlobalIndex = this._allMembers.Count;
            this._allMembers.Add(member);
            if (!(member.DefaultValue is DBNull) && member.DefaultValue != null)
            {
                if (this._membersWithDefault == null)
                {
                    this._membersWithDefault = new ArrayList();
                }
                this._membersWithDefault.Add(member);
            }
            if (member.IsReturnValue)
            {
                this._returnMember = member;
            }
            if (!(member is XmlTypeMapMemberAttribute))
            {
                if (member is XmlTypeMapMemberFlatList)
                {
                    this.RegisterFlatList((XmlTypeMapMemberFlatList)member);
                }
                else if (member is XmlTypeMapMemberAnyElement)
                {
                    XmlTypeMapMemberAnyElement xmlTypeMapMemberAnyElement = (XmlTypeMapMemberAnyElement)member;
                    if (xmlTypeMapMemberAnyElement.IsDefaultAny)
                    {
                        this._defaultAnyElement = xmlTypeMapMemberAnyElement;
                    }
                    if (xmlTypeMapMemberAnyElement.TypeData.IsListType)
                    {
                        this.RegisterFlatList(xmlTypeMapMemberAnyElement);
                    }
                }
                else
                {
                    if (member is XmlTypeMapMemberAnyAttribute)
                    {
                        this._defaultAnyAttribute = (XmlTypeMapMemberAnyAttribute)member;
                        return;
                    }
                    if (member is XmlTypeMapMemberNamespaces)
                    {
                        this._namespaceDeclarations = (XmlTypeMapMemberNamespaces)member;
                        return;
                    }
                }
                if (member is XmlTypeMapMemberElement && ((XmlTypeMapMemberElement)member).IsXmlTextCollector)
                {
                    if (this._xmlTextCollector != null)
                    {
                        throw new InvalidOperationException("XmlTextAttribute can only be applied once in a class");
                    }
                    this._xmlTextCollector = member;
                }
                if (this._elementMembers == null)
                {
                    this._elementMembers = new ArrayList();
                    this._elements       = new Hashtable();
                }
                member.Index = this._elementMembers.Count;
                this._elementMembers.Add(member);
                ICollection elementInfo = ((XmlTypeMapMemberElement)member).ElementInfo;
                foreach (object obj in elementInfo)
                {
                    XmlTypeMapElementInfo xmlTypeMapElementInfo = (XmlTypeMapElementInfo)obj;
                    string key = this.BuildKey(xmlTypeMapElementInfo.ElementName, xmlTypeMapElementInfo.Namespace);
                    if (this._elements.ContainsKey(key))
                    {
                        throw new InvalidOperationException(string.Concat(new string[]
                        {
                            "The XML element named '",
                            xmlTypeMapElementInfo.ElementName,
                            "' from namespace '",
                            xmlTypeMapElementInfo.Namespace,
                            "' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element."
                        }));
                    }
                    this._elements.Add(key, xmlTypeMapElementInfo);
                }
                if (member.TypeData.IsListType && member.TypeData.Type != null && !member.TypeData.Type.IsArray)
                {
                    if (this._listMembers == null)
                    {
                        this._listMembers = new ArrayList();
                    }
                    this._listMembers.Add(member);
                }
                return;
            }
            XmlTypeMapMemberAttribute xmlTypeMapMemberAttribute = (XmlTypeMapMemberAttribute)member;

            if (this._attributeMembers == null)
            {
                this._attributeMembers = new Hashtable();
            }
            string key2 = this.BuildKey(xmlTypeMapMemberAttribute.AttributeName, xmlTypeMapMemberAttribute.Namespace);

            if (this._attributeMembers.ContainsKey(key2))
            {
                throw new InvalidOperationException(string.Concat(new string[]
                {
                    "The XML attribute named '",
                    xmlTypeMapMemberAttribute.AttributeName,
                    "' from namespace '",
                    xmlTypeMapMemberAttribute.Namespace,
                    "' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the attribute."
                }));
            }
            member.Index = this._attributeMembers.Count;
            this._attributeMembers.Add(key2, member);
        }
		private XmlTypeMapMember CreateMapMember (XmlReflectionMember rmember, string defaultNamespace)
		{
			XmlTypeMapMember mapMember;
			XmlAttributes atts = rmember.XmlAttributes;
			TypeData typeData = TypeTranslator.GetTypeData (rmember.MemberType);

			if (atts.XmlAnyAttribute != null)
			{
				if ( (rmember.MemberType.FullName == "System.Xml.XmlAttribute[]") ||
					 (rmember.MemberType.FullName == "System.Xml.XmlNode[]") )
				{
					mapMember = new XmlTypeMapMemberAnyAttribute();
				}
				else
					throw new InvalidOperationException ("XmlAnyAttributeAttribute can only be applied to members of type XmlAttribute[] or XmlNode[]");
			}
			else if (atts.XmlAnyElements != null && atts.XmlAnyElements.Count > 0)
			{
				if ( (rmember.MemberType.FullName == "System.Xml.XmlElement[]") ||
					 (rmember.MemberType.FullName == "System.Xml.XmlNode[]") ||
					 (rmember.MemberType.FullName == "System.Xml.XmlElement"))
				{
					XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement();
					member.ElementInfo = ImportAnyElementInfo (defaultNamespace, rmember, member, atts);
					mapMember = member;
				}
				else
					throw new InvalidOperationException ("XmlAnyElementAttribute can only be applied to members of type XmlElement, XmlElement[] or XmlNode[]");
			}
			else if (atts.Xmlns)
			{
				XmlTypeMapMemberNamespaces mapNamespaces = new XmlTypeMapMemberNamespaces ();
				mapMember = mapNamespaces;
			}
			else if (atts.XmlAttribute != null)
			{
				// An attribute

				if (atts.XmlElements != null && atts.XmlElements.Count > 0)
					throw new Exception ("XmlAttributeAttribute and XmlElementAttribute cannot be applied to the same member");

				XmlTypeMapMemberAttribute mapAttribute = new XmlTypeMapMemberAttribute ();
				if (atts.XmlAttribute.AttributeName == null) 
					mapAttribute.AttributeName = rmember.MemberName;
				else 
					mapAttribute.AttributeName = atts.XmlAttribute.AttributeName;

				if (typeData.IsComplexType)
					mapAttribute.MappedType = ImportTypeMapping (typeData.Type, null, mapAttribute.Namespace);
				
				if (atts.XmlAttribute.Namespace != null && atts.XmlAttribute.Namespace != defaultNamespace)
				{
					if (atts.XmlAttribute.Form == XmlSchemaForm.Unqualified)
						throw new InvalidOperationException ("The Form property may not be 'Unqualified' when an explicit Namespace property is present");
					mapAttribute.Form = XmlSchemaForm.Qualified;
					mapAttribute.Namespace = atts.XmlAttribute.Namespace;
				}
				else
				{
					mapAttribute.Form = atts.XmlAttribute.Form;
					if (atts.XmlAttribute.Form == XmlSchemaForm.Qualified)
						mapAttribute.Namespace = defaultNamespace;
					else
						mapAttribute.Namespace = "";
				}
				
				typeData = TypeTranslator.GetTypeData(rmember.MemberType, atts.XmlAttribute.DataType);
				mapMember = mapAttribute;
			}
			else if (typeData.SchemaType == SchemaTypes.Array)
			{
				// If the member has a single XmlElementAttribute and the type is the type of the member,
				// then it is not a flat list
				
				if (atts.XmlElements.Count > 1 ||
				   (atts.XmlElements.Count == 1 && atts.XmlElements[0].Type != typeData.Type) ||
				   (atts.XmlText != null))
				{
					// A flat list

					// TODO: check that it does not have XmlArrayAttribute
					XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
					member.ListMap = new ListMap ();
					member.ListMap.ItemInfo = ImportElementInfo (rmember.MemberName, defaultNamespace, typeData.ListItemType, member, atts);
					member.ElementInfo = member.ListMap.ItemInfo;
					mapMember = member;
				}
				else
				{
					// A list

					XmlTypeMapMemberList member = new XmlTypeMapMemberList ();

					// Creates an ElementInfo that identifies the array instance. 
					member.ElementInfo = new XmlTypeMapElementInfoList();
					XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, typeData);
					elem.ElementName = (atts.XmlArray != null && atts.XmlArray.ElementName != null) ? atts.XmlArray.ElementName : rmember.MemberName;
					elem.Namespace = (atts.XmlArray != null && atts.XmlArray.Namespace != null) ? atts.XmlArray.Namespace : defaultNamespace;
					elem.MappedType = ImportListMapping (rmember.MemberType, null, elem.Namespace, atts, 0);
					elem.IsNullable = (atts.XmlArray != null) ? atts.XmlArray.IsNullable : false;
					elem.Form = (atts.XmlArray != null) ? atts.XmlArray.Form : XmlSchemaForm.Qualified;

					member.ElementInfo.Add (elem);
					mapMember = member;
				}
			}
			else
			{
				// An element

				XmlTypeMapMemberElement member = new XmlTypeMapMemberElement ();
				member.ElementInfo = ImportElementInfo (rmember.MemberName, defaultNamespace, rmember.MemberType, member, atts);
				mapMember = member;
			}

			mapMember.DefaultValue = atts.XmlDefaultValue;
			mapMember.TypeData = typeData;
			mapMember.Name = rmember.MemberName;
			mapMember.IsReturnValue = rmember.IsReturnValue;
			return mapMember;
		}