SetSequence() private method

private SetSequence ( ) : void
return void
Example #1
0
 internal void SetSequence()
 {
     for (int i = 0; i < members.Length; i++)
     {
         if (members[i].IsParticle)
         {
             members[i].SequenceId = i;
         }
     }
     if (baseMapping != null)
     {
         baseMapping.SetSequence();
     }
 }
 internal void SetSequence()
 {
     if (!base.TypeDesc.IsRoot)
     {
         StructMapping baseMapping = this;
         while ((!baseMapping.BaseMapping.IsSequence && (baseMapping.BaseMapping != null)) && !baseMapping.BaseMapping.TypeDesc.IsRoot)
         {
             baseMapping = baseMapping.BaseMapping;
         }
         baseMapping.IsSequence = true;
         for (StructMapping mapping2 = baseMapping.DerivedMappings; mapping2 != null; mapping2 = mapping2.NextDerivedMapping)
         {
             mapping2.SetSequence();
         }
     }
 }
Example #3
0
        internal void SetSequence()
        {
            if (TypeDesc.IsRoot)
            {
                return;
            }

            StructMapping start = this;

            // find first mapping that does not have the sequence set
            while (start.BaseMapping != null && !start.BaseMapping.IsSequence && !start.BaseMapping.TypeDesc.IsRoot)
            {
                start = start.BaseMapping;
            }

            start.IsSequence = true;
            for (StructMapping derived = start.DerivedMappings; derived != null; derived = derived.NextDerivedMapping)
            {
                derived.SetSequence();
            }
        }
Example #4
0
        private StructMapping ImportStructType(XmlSchemaType type, string typeNs, string identifier, Type baseType, bool arrayLike)
        {
            TypeDesc baseTypeDesc = null;
            TypeMapping baseMapping = null;

            bool isRootType = false;
            if (!type.DerivedFrom.IsEmpty)
            {
                baseMapping = ImportType(type.DerivedFrom, typeof(TypeMapping), null, TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue, false);

                if (baseMapping is StructMapping)
                    baseTypeDesc = ((StructMapping)baseMapping).TypeDesc;
                else if (baseMapping is ArrayMapping)
                {
                    baseMapping = ((ArrayMapping)baseMapping).TopLevelMapping;
                    if (baseMapping != null)
                    {
                        baseMapping.ReferencedByTopLevelElement = false;
                        baseMapping.ReferencedByElement = true;
                        baseTypeDesc = baseMapping.TypeDesc;
                    }
                }
                else
                    baseMapping = null;
            }
            if (baseTypeDesc == null && baseType != null)
                baseTypeDesc = Scope.GetTypeDesc(baseType);
            if (baseMapping == null)
            {
                baseMapping = GetRootMapping();
                isRootType = true;
            }
            Mapping previousMapping = (Mapping)ImportedMappings[type];
            if (previousMapping != null)
            {
                if (previousMapping is StructMapping)
                {
                    return (StructMapping)previousMapping;
                }
                else if (arrayLike && previousMapping is ArrayMapping)
                {
                    ArrayMapping arrayMapping = (ArrayMapping)previousMapping;
                    if (arrayMapping.TopLevelMapping != null)
                    {
                        return arrayMapping.TopLevelMapping;
                    }
                }
                else
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlTypeUsedTwice, type.QualifiedName.Name, type.QualifiedName.Namespace));
                }
            }
            StructMapping structMapping = new StructMapping();
            structMapping.IsReference = Schemas.IsReference(type);
            TypeFlags flags = TypeFlags.Reference;
            if (type is XmlSchemaComplexType)
            {
                if (((XmlSchemaComplexType)type).IsAbstract)
                    flags |= TypeFlags.Abstract;
            }

            identifier = Accessor.UnescapeName(identifier);
            string typeName = type.Name == null || type.Name.Length == 0 ? GenerateUniqueTypeName(identifier, typeNs) : GenerateUniqueTypeName(identifier);
            structMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Struct, baseTypeDesc, flags);
            structMapping.Namespace = typeNs;
            structMapping.TypeName = type.Name == null || type.Name.Length == 0 ? null : identifier;
            structMapping.BaseMapping = (StructMapping)baseMapping;
            if (!arrayLike)
                ImportedMappings.Add(type, structMapping);
            CodeIdentifiers members = new CodeIdentifiers();
            CodeIdentifiers membersScope = structMapping.BaseMapping.Scope.Clone();
            members.AddReserved(typeName);
            membersScope.AddReserved(typeName);
            AddReservedIdentifiersForDataBinding(members);
            if (isRootType)
                AddReservedIdentifiersForDataBinding(membersScope);
            bool needExplicitOrder = false;
            structMapping.Members = ImportTypeMembers(type, typeNs, identifier, members, membersScope, structMapping, ref needExplicitOrder, true, true);

            if (!IsAllGroup(type))
            {
                if (needExplicitOrder && !GenerateOrder)
                {
                    structMapping.SetSequence();
                }
                else if (GenerateOrder)
                {
                    structMapping.IsSequence = true;
                }
            }

            for (int i = 0; i < structMapping.Members.Length; i++)
            {
                StructMapping declaringMapping;
                MemberMapping baseMember = ((StructMapping)baseMapping).FindDeclaringMapping(structMapping.Members[i], out declaringMapping, structMapping.TypeName);
                if (baseMember != null && baseMember.TypeDesc != structMapping.Members[i].TypeDesc)
                    throw new InvalidOperationException(SR.Format(SR.XmlIllegalOverride, type.Name, baseMember.Name, baseMember.TypeDesc.FullName, structMapping.Members[i].TypeDesc.FullName, declaringMapping.TypeDesc.FullName));
            }
            structMapping.Scope = membersScope;
            Scope.AddTypeMapping(structMapping);
            return structMapping;
        }
 private StructMapping ImportStructType(XmlSchemaType type, string typeNs, string identifier, Type baseType, bool arrayLike)
 {
     TypeDesc baseTypeDesc = null;
     TypeMapping topLevelMapping = null;
     bool flag = false;
     if (!type.DerivedFrom.IsEmpty)
     {
         topLevelMapping = this.ImportType(type.DerivedFrom, typeof(TypeMapping), null, TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue, false);
         if (topLevelMapping is StructMapping)
         {
             baseTypeDesc = ((StructMapping) topLevelMapping).TypeDesc;
         }
         else if (topLevelMapping is ArrayMapping)
         {
             topLevelMapping = ((ArrayMapping) topLevelMapping).TopLevelMapping;
             if (topLevelMapping != null)
             {
                 topLevelMapping.ReferencedByTopLevelElement = false;
                 topLevelMapping.ReferencedByElement = true;
                 baseTypeDesc = topLevelMapping.TypeDesc;
             }
         }
         else
         {
             topLevelMapping = null;
         }
     }
     if ((baseTypeDesc == null) && (baseType != null))
     {
         baseTypeDesc = base.Scope.GetTypeDesc(baseType);
     }
     if (topLevelMapping == null)
     {
         topLevelMapping = base.GetRootMapping();
         flag = true;
     }
     Mapping mapping2 = (Mapping) base.ImportedMappings[type];
     if (mapping2 != null)
     {
         if (mapping2 is StructMapping)
         {
             return (StructMapping) mapping2;
         }
         if (!arrayLike || !(mapping2 is ArrayMapping))
         {
             throw new InvalidOperationException(Res.GetString("XmlTypeUsedTwice", new object[] { type.QualifiedName.Name, type.QualifiedName.Namespace }));
         }
         ArrayMapping mapping3 = (ArrayMapping) mapping2;
         if (mapping3.TopLevelMapping != null)
         {
             return mapping3.TopLevelMapping;
         }
     }
     StructMapping mapping4 = new StructMapping {
         IsReference = base.Schemas.IsReference(type)
     };
     TypeFlags reference = TypeFlags.Reference;
     if ((type is XmlSchemaComplexType) && ((XmlSchemaComplexType) type).IsAbstract)
     {
         reference |= TypeFlags.Abstract;
     }
     identifier = Accessor.UnescapeName(identifier);
     string name = ((type.Name == null) || (type.Name.Length == 0)) ? this.GenerateUniqueTypeName(identifier, typeNs) : base.GenerateUniqueTypeName(identifier);
     mapping4.TypeDesc = new TypeDesc(name, name, TypeKind.Struct, baseTypeDesc, reference);
     mapping4.Namespace = typeNs;
     mapping4.TypeName = ((type.Name == null) || (type.Name.Length == 0)) ? null : identifier;
     mapping4.BaseMapping = (StructMapping) topLevelMapping;
     if (!arrayLike)
     {
         base.ImportedMappings.Add(type, mapping4);
     }
     CodeIdentifiers scope = new CodeIdentifiers();
     CodeIdentifiers identifiers2 = mapping4.BaseMapping.Scope.Clone();
     scope.AddReserved(name);
     identifiers2.AddReserved(name);
     base.AddReservedIdentifiersForDataBinding(scope);
     if (flag)
     {
         base.AddReservedIdentifiersForDataBinding(identifiers2);
     }
     bool needExplicitOrder = false;
     mapping4.Members = this.ImportTypeMembers(type, typeNs, identifier, scope, identifiers2, mapping4, ref needExplicitOrder, true, true);
     if (!this.IsAllGroup(type))
     {
         if (needExplicitOrder && !this.GenerateOrder)
         {
             mapping4.SetSequence();
         }
         else if (this.GenerateOrder)
         {
             mapping4.IsSequence = true;
         }
     }
     for (int i = 0; i < mapping4.Members.Length; i++)
     {
         StructMapping mapping5;
         MemberMapping mapping6 = ((StructMapping) topLevelMapping).FindDeclaringMapping(mapping4.Members[i], out mapping5, mapping4.TypeName);
         if ((mapping6 != null) && (mapping6.TypeDesc != mapping4.Members[i].TypeDesc))
         {
             throw new InvalidOperationException(Res.GetString("XmlIllegalOverride", new object[] { type.Name, mapping6.Name, mapping6.TypeDesc.FullName, mapping4.Members[i].TypeDesc.FullName, mapping5.TypeDesc.FullName }));
         }
     }
     mapping4.Scope = identifiers2;
     base.Scope.AddTypeMapping(mapping4);
     return mapping4;
 }