private void CreateArrayElementsFromAttributes(ArrayMapping arrayMapping, XmlArrayItemAttributes attributes, Type arrayElementType, string arrayElementNs, RecursionLimiter limiter) { System.Xml.Serialization.NameTable scope = new System.Xml.Serialization.NameTable(); for (int i = 0; (attributes != null) && (i < attributes.Count); i++) { XmlArrayItemAttribute attribute = attributes[i]; if (attribute.NestingLevel == this.arrayNestingLevel) { ElementAccessor accessor; Type type = (attribute.Type != null) ? attribute.Type : arrayElementType; TypeDesc typeDesc = this.typeScope.GetTypeDesc(type); accessor = new ElementAccessor { Namespace = (attribute.Namespace == null) ? arrayElementNs : attribute.Namespace, Mapping = this.ImportTypeMapping(this.modelScope.GetTypeModel(type), accessor.Namespace, ImportContext.Element, attribute.DataType, null, limiter), Name = (attribute.ElementName.Length == 0) ? accessor.Mapping.DefaultElementName : XmlConvert.EncodeLocalName(attribute.ElementName), IsNullable = attribute.IsNullableSpecified ? attribute.IsNullable : (typeDesc.IsNullable || typeDesc.IsOptionalValue), Form = (attribute.Form == XmlSchemaForm.None) ? XmlSchemaForm.Qualified : attribute.Form }; CheckForm(accessor.Form, arrayElementNs != accessor.Namespace); CheckNullable(accessor.IsNullable, typeDesc, accessor.Mapping); AddUniqueAccessor(scope, accessor); } } arrayMapping.Elements = (ElementAccessor[]) scope.ToArray(typeof(ElementAccessor)); }
private MemberMapping ImportChoiceGroup(XmlSchemaGroupBase group, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, string ns, bool groupRepeats, ref bool needExplicitOrder, bool allowDuplicates) { System.Xml.Serialization.NameTable choiceElements = new System.Xml.Serialization.NameTable(); if (this.GatherGroupChoices(group, choiceElements, identifier, ns, ref needExplicitOrder, allowDuplicates)) { groupRepeats = true; } MemberMapping mapping = new MemberMapping { Elements = (ElementAccessor[]) choiceElements.ToArray(typeof(ElementAccessor)) }; Array.Sort(mapping.Elements, new ElementComparer()); this.AddScopeElements(elementsScope, mapping.Elements, ref needExplicitOrder, allowDuplicates); bool flag = false; bool flag2 = false; Hashtable hashtable = new Hashtable(mapping.Elements.Length); for (int i = 0; i < mapping.Elements.Length; i++) { ElementAccessor accessor = mapping.Elements[i]; string fullName = accessor.Mapping.TypeDesc.FullName; object obj2 = hashtable[fullName]; if (obj2 != null) { flag = true; ElementAccessor accessor2 = (ElementAccessor) obj2; if (!flag2 && (accessor2.IsNullable != accessor.IsNullable)) { flag2 = true; } } else { hashtable.Add(fullName, accessor); } ArrayMapping arrayMapping = accessor.Mapping as ArrayMapping; if ((arrayMapping != null) && this.IsNeedXmlSerializationAttributes(arrayMapping)) { accessor.Mapping = arrayMapping.TopLevelMapping; accessor.Mapping.ReferencedByTopLevelElement = false; accessor.Mapping.ReferencedByElement = true; } } if (flag2) { mapping.TypeDesc = base.Scope.GetTypeDesc(typeof(object)); } else { TypeDesc[] typeDescs = new TypeDesc[hashtable.Count]; IEnumerator enumerator = hashtable.Values.GetEnumerator(); for (int j = 0; j < typeDescs.Length; j++) { if (!enumerator.MoveNext()) { break; } typeDescs[j] = ((ElementAccessor) enumerator.Current).Mapping.TypeDesc; } mapping.TypeDesc = TypeDesc.FindCommonBaseTypeDesc(typeDescs); if (mapping.TypeDesc == null) { mapping.TypeDesc = base.Scope.GetTypeDesc(typeof(object)); } } if (groupRepeats) { mapping.TypeDesc = mapping.TypeDesc.CreateArrayTypeDesc(); } if (membersScope != null) { mapping.Name = membersScope.AddUnique(groupRepeats ? "Items" : "Item", mapping); if (members != null) { members.Add(mapping.Name, mapping); } } if (flag) { mapping.ChoiceIdentifier = new ChoiceIdentifierAccessor(); mapping.ChoiceIdentifier.MemberName = mapping.Name + "ElementName"; mapping.ChoiceIdentifier.Mapping = this.ImportEnumeratedChoice(mapping.Elements, ns, mapping.Name + "ChoiceType"); mapping.ChoiceIdentifier.MemberIds = new string[mapping.Elements.Length]; ConstantMapping[] constants = ((EnumMapping) mapping.ChoiceIdentifier.Mapping).Constants; for (int k = 0; k < mapping.Elements.Length; k++) { mapping.ChoiceIdentifier.MemberIds[k] = constants[k].Name; } MemberMapping mapping3 = new MemberMapping { Ignore = true, Name = mapping.ChoiceIdentifier.MemberName }; if (groupRepeats) { mapping3.TypeDesc = mapping.ChoiceIdentifier.Mapping.TypeDesc.CreateArrayTypeDesc(); } else { mapping3.TypeDesc = mapping.ChoiceIdentifier.Mapping.TypeDesc; } ElementAccessor accessor3 = new ElementAccessor { Name = mapping3.Name, Namespace = ns, Mapping = mapping.ChoiceIdentifier.Mapping }; mapping3.Elements = new ElementAccessor[] { accessor3 }; if (membersScope != null) { accessor3.Name = mapping3.Name = mapping.ChoiceIdentifier.MemberName = membersScope.AddUnique(mapping.ChoiceIdentifier.MemberName, mapping3); if (members != null) { members.Add(accessor3.Name, mapping3); } } } return mapping; }