상속: ClrTypeInfo
예제 #1
0
 private void TraverseAttributes(XmlSchemaObjectTable derivedAttributes, ClrContentTypeInfo typeInfo)
 {
     foreach (XmlSchemaAttribute derivedAttribute in derivedAttributes.Values)
     {
         Debug.Assert(derivedAttribute.AttributeSchemaType != null); //For use=prohibited, without derivation it doesnt mean anything, hence attribute should be compiled
         ClrBasePropertyInfo propertyInfo = BuildProperty(derivedAttribute, false, false);
         BuildAnnotationInformation(propertyInfo, derivedAttribute, false, false);
         typeInfo.AddMember(propertyInfo);
     }
 }
        internal void ElementsToTypes()
        {
            bool isRoot            = false;
            int  rootElementsCount = this.schemas.GlobalElements.Count;

            foreach (XmlSchemaElement elem in this.schemas.GlobalElements.Values)
            {
                SymbolEntry      symbol       = this.symbolTable.AddElement(elem);
                XmlSchemaType    schemaType   = elem.ElementSchemaType;
                string           xsdNamespace = elem.QualifiedName.Namespace;
                ClrTypeInfo      typeInfo     = null;
                XmlSchemaElement headElement  = null;
                if (!elem.SubstitutionGroup.IsEmpty)
                {
                    headElement = (XmlSchemaElement)this.schemas.GlobalElements[elem.SubstitutionGroup];
                }
                if (!schemaType.IsGlobal())
                {
                    ClrContentTypeInfo ctypeInfo = new ClrContentTypeInfo();
                    this.localSymbolTable.Init(symbol.identifierName);
                    ctypeInfo.baseType = headElement;
                    this.BuildProperties(elem, schemaType, ctypeInfo);
                    this.BuildNestedTypes(ctypeInfo);
                    typeInfo = ctypeInfo;
                }
                else
                {
                    ClrWrapperTypeInfo wtypeInfo = new ClrWrapperTypeInfo((headElement == null ? false : headElement.ElementSchemaType == schemaType));
                    ClrTypeReference   typeDef   = this.BuildTypeReference(schemaType, schemaType.QualifiedName, false, true);
                    wtypeInfo.InnerType = typeDef;
                    typeInfo            = wtypeInfo;
                    typeInfo.baseType   = headElement;
                }
                if (!isRoot)
                {
                    if ((rootElementsCount == 1 ? true : this.CheckUnhandledAttributes(elem)))
                    {
                        typeInfo.IsRoot = true;
                        isRoot          = true;
                    }
                }
                typeInfo.IsSubstitutionHead = this.IsSubstitutionGroupHead(elem) != null;
                typeInfo.IsAbstract         = elem.IsAbstract;
                typeInfo.clrtypeName        = symbol.identifierName;
                typeInfo.clrtypeNs          = symbol.clrNamespace;
                typeInfo.schemaName         = symbol.symbolName;
                typeInfo.schemaNs           = xsdNamespace;
                typeInfo.typeOrigin         = SchemaOrigin.Element;
                this.BuildAnnotationInformation(typeInfo, schemaType);
                this.binding.Types.Add(typeInfo);
            }
        }
예제 #3
0
        internal void TypesToTypes()
        {
            foreach (XmlSchemaType st in schemas.GlobalTypes.Values)
            {
                XmlSchemaSimpleType simpleType = st as XmlSchemaSimpleType;
                if (simpleType != null)
                {
                    SymbolEntry symbol       = symbolTable.AddType(simpleType);
                    string      xsdNamespace = simpleType.QualifiedName.Namespace;
                    ClrSimpleTypeInfo
                        typeInfo = ClrSimpleTypeInfo
                                   .CreateSimpleTypeInfo(simpleType); //Create corresponding simple type info objects
                    typeInfo.IsAbstract  = false;
                    typeInfo.clrtypeName = symbol.identifierName;
                    typeInfo.clrtypeNs   = symbol.clrNamespace;
                    typeInfo.schemaName  = symbol.symbolName;
                    typeInfo.schemaNs    = xsdNamespace;
                    typeInfo.typeOrigin  = SchemaOrigin.Fragment;
                    BuildAnnotationInformation(typeInfo, st);
                    binding.Types.Add(typeInfo);
                }
                else
                {
                    XmlSchemaComplexType ct = st as XmlSchemaComplexType;
                    if (ct != null && ct.TypeCode != XmlTypeCode.Item)
                    {
                        SymbolEntry symbol       = symbolTable.AddType(ct);
                        string      xsdNamespace = ct.QualifiedName.Namespace;

                        localSymbolTable.Init(symbol.identifierName);

                        ClrContentTypeInfo typeInfo = new ClrContentTypeInfo();
                        typeInfo.IsAbstract  = ct.IsAbstract;
                        typeInfo.IsSealed    = ct.IsFinal();
                        typeInfo.clrtypeName = symbol.identifierName;
                        typeInfo.clrtypeNs   = symbol.clrNamespace;
                        typeInfo.schemaName  = symbol.symbolName;
                        typeInfo.schemaNs    = xsdNamespace;

                        typeInfo.typeOrigin = SchemaOrigin.Fragment;
                        typeInfo.baseType   = BaseType(ct);
                        BuildProperties(null, ct, typeInfo);
                        BuildNestedTypes(typeInfo);
                        BuildAnnotationInformation(typeInfo, ct);
                        binding.Types.Add(typeInfo);
                    }
                }
            }
        }
예제 #4
0
        internal void ElementsToTypes()
        {
            bool isRoot = false;
            int rootElementsCount = schemas.GlobalElements.Count;
            foreach (XmlSchemaElement elem in schemas.GlobalElements.Values)
            {
                SymbolEntry symbol = symbolTable.AddElement(elem);
                XmlSchemaType schemaType = elem.ElementSchemaType;
                string xsdNamespace = elem.QualifiedName.Namespace;

                ClrTypeInfo typeInfo = null;
                XmlSchemaElement headElement = null;

                if (!elem.SubstitutionGroup.IsEmpty)
                {
                    headElement =
                        (XmlSchemaElement)schemas.GlobalElements[
                            elem.SubstitutionGroup];
                }

                if (schemaType.IsGlobal())
                {
                    //Global elem with global type, generate wrapper class for the element
                    bool hasBaseContentType =
                        headElement != null &&
                        headElement.ElementSchemaType == schemaType;
                    ClrWrapperTypeInfo wtypeInfo = new ClrWrapperTypeInfo(
                        hasBaseContentType);
                    ClrTypeReference typeDef = BuildTypeReference(
                        schemaType, schemaType.QualifiedName, false, true);
                    //Save the fixed/default value of the element
                    wtypeInfo.InnerType = typeDef;
                    typeInfo = wtypeInfo;
                    //If element is member of substitutionGroup, add derivation step
                    typeInfo.baseType = headElement;
                }
                else
                {
                    ClrContentTypeInfo ctypeInfo = new ClrContentTypeInfo();
                    localSymbolTable.Init(symbol.identifierName);
                    // If element is member of substitutionGroup, add derivation step
                    ctypeInfo.baseType = headElement;
                    BuildProperties(elem, schemaType, ctypeInfo);
                    BuildNestedTypes(ctypeInfo);
                    typeInfo = ctypeInfo;
                }

                if (!isRoot)
                {
                    if (rootElementsCount == 1 || CheckUnhandledAttributes(elem))
                    {
                        typeInfo.IsRoot = true;
                        isRoot = true;
                    }
                }

                typeInfo.IsSubstitutionHead = IsSubstitutionGroupHead(elem) != null;
                typeInfo.IsAbstract = elem.IsAbstract;
                typeInfo.clrtypeName = symbol.identifierName;
                typeInfo.clrtypeNs = symbol.clrNamespace;
                typeInfo.schemaName = symbol.symbolName;
                typeInfo.schemaNs = xsdNamespace;

                typeInfo.typeOrigin = SchemaOrigin.Element;

                BuildAnnotationInformation(typeInfo, schemaType);
                binding.Types.Add(typeInfo);
            }
        }
예제 #5
0
        private CodeTypeDeclaration ProcessType(ClrContentTypeInfo typeInfo, string parentIdentifier, bool globalType)
        {
            SetFullTypeName(typeInfo, parentIdentifier);

            if(globalType) {
                currentNamespace = typeInfo.clrtypeNs;
            }
            //Build type using TypeBuilder
            typeBuilder = GetTypeBuilder();
            typeBuilder.CreateTypeDeclaration(typeInfo);
            ProcessProperties(typeInfo.Content, typeInfo.Annotations);
            typeBuilder.CreateFunctionalConstructor(typeInfo.Annotations);
            typeBuilder.ImplementInterfaces(settings.EnableServiceReference);
            typeBuilder.ApplyAnnotations(typeInfo);
            if (globalType) {
                if (typeInfo.typeOrigin == SchemaOrigin.Fragment) {
                    typeBuilder.AddTypeToTypeManager(typeDictionaryAddStatements, Constants.TypeDictionaryField);
                }
                else {
                    typeBuilder.AddTypeToTypeManager(elementDictionaryAddStatements, Constants.ElementDictionaryField);
                }
            }
            CodeTypeDeclaration builtType = typeBuilder.TypeDeclaration;
            ProcessNestedTypes(typeInfo.NestedTypes, builtType, typeInfo.clrFullTypeName);
            return builtType;
        }
예제 #6
0
        internal void TypesToTypes()
        {
            foreach (XmlSchemaType st in schemas.GlobalTypes.Values)
            {
                XmlSchemaSimpleType simpleType = st as XmlSchemaSimpleType;
                if (simpleType != null)
                {
                    SymbolEntry symbol = symbolTable.AddType(simpleType);
                    string xsdNamespace = simpleType.QualifiedName.Namespace;
                    ClrSimpleTypeInfo typeInfo = ClrSimpleTypeInfo.CreateSimpleTypeInfo(simpleType);//Create corresponding simple type info objects
                    typeInfo.IsAbstract = false;
                    typeInfo.clrtypeName = symbol.identifierName;
                    typeInfo.clrtypeNs = symbol.clrNamespace;
                    typeInfo.schemaName = symbol.symbolName;
                    typeInfo.schemaNs = xsdNamespace;
                    typeInfo.typeOrigin = SchemaOrigin.Fragment;
                    BuildAnnotationInformation(typeInfo, st);
                    binding.Types.Add(typeInfo);
                }
                else
                {
                    XmlSchemaComplexType ct = st as XmlSchemaComplexType;
                    if (ct != null && ct.TypeCode != XmlTypeCode.Item)
                    {
                        SymbolEntry symbol = symbolTable.AddType(ct);
                        string xsdNamespace = ct.QualifiedName.Namespace;

                        localSymbolTable.Init(symbol.identifierName);

                        ClrContentTypeInfo typeInfo = new ClrContentTypeInfo();
                        typeInfo.IsAbstract = ct.IsAbstract;
                        typeInfo.IsSealed = ct.IsFinal();
                        typeInfo.clrtypeName = symbol.identifierName;
                        typeInfo.clrtypeNs = symbol.clrNamespace;
                        typeInfo.schemaName = symbol.symbolName;
                        typeInfo.schemaNs = xsdNamespace;

                        typeInfo.typeOrigin = SchemaOrigin.Fragment;
                        typeInfo.baseType = BaseType(ct);
                        BuildProperties(null, ct, typeInfo);
                        BuildNestedTypes(typeInfo);
                        BuildAnnotationInformation(typeInfo, ct);
                        binding.Types.Add(typeInfo);
                    }
                }
            }
        }
        private void TraverseParticle(XmlSchemaParticle particle, XmlSchemaComplexType baseType,
                                      ClrContentTypeInfo typeInfo, XmlSchemaDerivationMethod derivationMethod)
        {
            if (particleStack == null)
            {
                particleStack = new Stack <ParticleData>();
            }
            else
            {
                particleStack.Clear();
            }

            if (propertyNameTypeTable == null)
            {
                propertyNameTypeTable = new Dictionary <string, ClrPropertyInfo>();
            }
            else
            {
                propertyNameTypeTable.Clear();
            }

            XmlSchemaParticle baseParticle = baseType.ContentTypeParticle;
            ParticleData      particleData;
            GroupingInfo      parentGroupInfo = null;
            StringBuilder     regEx           = new StringBuilder();

            XmlSchemaGroupBase currentGroupBase    = null;
            GroupingInfo       currentGroupingInfo = null;

            int currentIndex = 0;

            while (true)
            {
                // dont interrogate a particle if we are past the end of the list
                if (currentGroupBase == null || currentIndex <= currentGroupBase.Items.Count)
                {
                    ParticleType particleType = particle.GetParticleType();
                    switch (particleType)
                    {
                    case ParticleType.Element:
                    {
                        XmlSchemaElement elem         = particle as XmlSchemaElement;
                        ClrPropertyInfo  propertyInfo = null;
                        bool             fromBaseType = false;
                        if (derivationMethod == XmlSchemaDerivationMethod.Extension && typeInfo.IsDerived)
                        {
                            if (baseParticle.ContainsElement(elem))
                            {
                                fromBaseType = true;
                            }
                            else if (!typeInfo.InlineBaseType && baseType.ContainsName(elem.QualifiedName))
                            {
                                typeInfo.InlineBaseType = true;
                            }
                        }

                        propertyInfo = BuildProperty(elem, fromBaseType);
                        regEx.Append(propertyInfo.PropertyName);
                        AppendOccurenceToRegex(propertyInfo, regEx);
                        //Add to parent
                        if (currentGroupingInfo == null)
                        {
                            //Not adding property to propertyNameTypeTable as this case will occur only for pointless groups, so they have just one property
                            BuildAnnotationInformation(propertyInfo, elem, false, false);
                            typeInfo.AddMember(propertyInfo);
                        }
                        else
                        {
                            BuildAnnotationInformation(propertyInfo, elem,
                                                       currentGroupingInfo.ContentModelType == ContentModelType.Choice,
                                                       currentGroupingInfo.IsNested);
                            currentGroupingInfo.AddChild(propertyInfo);
                            SetPropertyFlags(propertyInfo, currentGroupingInfo, elem.ElementSchemaType);
                        }

                        break;
                    }

                    case ParticleType.Any:
                    {
                        regEx.Append("any");
                        XmlSchemaAny any = particle as XmlSchemaAny;

                        if (derivationMethod == XmlSchemaDerivationMethod.Extension && typeInfo.IsDerived)
                        {
                            if (baseParticle.ContainsWildCard(any))
                            {
                                typeInfo.HasElementWildCard = true;     //ANY property in the base type will be reused
                            }
                        }

                        //Note we always create a property info object to keep the original nesting structure in the schema
                        //so it can be used to create a correct FSM; on the other hand, typeInfo.HasElementWildCard will indicate whether
                        //we need to create a property in the resulting object type.
                        ClrWildCardPropertyInfo wcPropertyInfo =
                            BuildAnyProperty(any, !typeInfo.HasElementWildCard);


                        //Add to parent
                        if (currentGroupingInfo == null)
                        {
                            typeInfo.AddMember(wcPropertyInfo);
                        }
                        else
                        {
                            currentGroupingInfo.AddChild(wcPropertyInfo);
                        }

                        if (!typeInfo.HasElementWildCard)
                        {
                            typeInfo.HasElementWildCard = true;
                        }
                        break;
                    }

                    case ParticleType.Sequence:
                    case ParticleType.Choice:
                    case ParticleType.All:
                        regEx.Append("(");
                        if (currentGroupBase != null)
                        {
                            //already there is a group that we are processing, push it on stack to process sub-group
                            particleStack.Push(
                                new ParticleData(currentGroupBase, currentGroupingInfo, currentIndex));
                            currentIndex = 0;     //Re-start index for new group base
                        }

                        parentGroupInfo  = currentGroupingInfo;    //Assign parent before creating child groupInfo
                        currentGroupBase = particle as XmlSchemaGroupBase;
                        Debug.Assert(currentGroupBase != null);
                        currentGroupingInfo = new GroupingInfo((ContentModelType)((int)particleType),
                                                               GetOccurence(currentGroupBase));

                        //Add to parent
                        if (parentGroupInfo == null)
                        {
                            typeInfo.AddMember(currentGroupingInfo);
                            parentGroupInfo = currentGroupingInfo;     //Assign first time
                        }
                        else
                        {
                            parentGroupInfo.AddChild(currentGroupingInfo);
                            parentGroupInfo.HasChildGroups = true;
                            currentGroupingInfo.IsNested   = true;
                            if (parentGroupInfo.IsRepeating)
                            {
                                currentGroupingInfo.IsRepeating = true;
                            }

                            if (currentGroupingInfo.IsRepeating)
                            {
                                parentGroupInfo.HasRepeatingGroups = true;
                            }
                        }

                        break;
                    }
                }

                //Drill down into items
                if (currentGroupBase != null && currentIndex < currentGroupBase.Items.Count)
                {
                    // if this isnt the first, then we need a seperator
                    if (currentIndex > 0)
                    {
                        regEx.Append(currentGroupingInfo.ContentModelType == ContentModelType.Choice ? " | " : ", ");
                    }

                    particle = (XmlSchemaParticle)currentGroupBase.Items[currentIndex++];
                }
                else
                {
                    if (currentGroupBase != null)
                    {
                        regEx.Append(")");
                        AppendOccurenceToRegex(currentGroupingInfo, regEx);
                    }

                    if (particleStack.Count > 0)
                    {
                        bool childGroupHasRecurringElements = currentGroupingInfo.HasRecurrentElements;
                        bool childGroupHasRepeatingGroups   = currentGroupingInfo.HasRepeatingGroups;

                        particleData        = particleStack.Pop();
                        currentGroupBase    = particleData.currentGroupBase;
                        currentGroupingInfo = particleData.currentGroupingInfo;

                        currentGroupingInfo.HasRecurrentElements = childGroupHasRecurringElements;
                        currentGroupingInfo.HasRepeatingGroups   = childGroupHasRepeatingGroups;

                        currentIndex = particleData.currentIndex;
                        if (currentIndex < currentGroupBase.Items.Count)
                        {
                            particle = (XmlSchemaParticle)currentGroupBase.Items[currentIndex++];
                            regEx.Append(currentGroupingInfo.ContentModelType == ContentModelType.Choice ? "|" : ", ");
                        }
                        else
                        {
                            // we were already at the end of the parent group, so just continue
                            currentIndex++; //we are off the end of this list
                        }
                    }
                    else
                    {
                        //No more particles to process
                        break;
                    }
                }
            }

            if (regEx.Length != 0)
            {
                typeInfo.ContentModelRegEx = regEx.ToString();
            }
        }
예제 #8
0
 private void TraverseAttributes(XmlSchemaObjectTable derivedAttributes, XmlSchemaObjectTable baseAttributes, ClrContentTypeInfo typeInfo)
 {
     foreach (XmlSchemaAttribute derivedAttribute in derivedAttributes.Values)
     {
         if (derivedAttribute.Use == XmlSchemaUse.Prohibited)
         {
             continue;
         }
         XmlSchemaAttribute baseAttribute = baseAttributes[derivedAttribute.QualifiedName] as XmlSchemaAttribute;
         if (baseAttribute != null && baseAttribute == derivedAttribute)
         {
             // Its the one copied from the base
             // http://linqtoxsd.codeplex.com/WorkItem/View.aspx?WorkItemId=3064
             ClrBasePropertyInfo propertyInfo = BuildProperty(
                 derivedAttribute, typeInfo.IsDerived, false);
             BuildAnnotationInformation(propertyInfo, derivedAttribute, false, false);
             typeInfo.AddMember(propertyInfo);
         }
         else
         {
             ClrBasePropertyInfo propertyInfo = BuildProperty(derivedAttribute, false, baseAttribute != null);
             BuildAnnotationInformation(propertyInfo, derivedAttribute, false, false);
             typeInfo.AddMember(propertyInfo);
         }
     }
 }
예제 #9
0
 private void BuildProperties(XmlSchemaElement parentElement, XmlSchemaType schemaType, ClrContentTypeInfo typeInfo)
 {
     XmlSchemaComplexType ct = schemaType as XmlSchemaComplexType;
     if (ct != null)
     {
         if (ct.TypeCode == XmlTypeCode.Item)
         {
             return;
         }
         XmlSchemaParticle particleToProperties = ct.ContentTypeParticle;
         XmlSchemaComplexType baseType = ct.BaseXmlSchemaType as XmlSchemaComplexType;
         if (schemaType.GetContentType() == XmlSchemaContentType.TextOnly)
         {
             //Try to create a text property for the simple content
             ClrPropertyInfo property = BuildComplexTypeTextProperty(parentElement, ct);
             if (property != null)
             {
                 typeInfo.AddMember(property);
             }
             if (baseType == null)
             { //Derived from Simple type, first step simpleContent extension
                 TraverseAttributes(ct.AttributeUses, typeInfo);
             }
             else
             { //Derived from another complex type simple content, generate the content only if there are additional restrictions
                 if (!ct.IsDerivedByRestriction()) //process attributes only if not derived by restriction
                     TraverseAttributes(ct.AttributeUses, baseType.AttributeUses, typeInfo);
             }
         }
         else
         {
             Debug.Assert(baseType != null); //ComplexType with complexContent is always derived from another complexType
             if (ct.IsDerivedByRestriction())
             {//Do not handle restrictions on complex content?
                 return;
             }
             if (particleToProperties.GetParticleType() != ParticleType.Empty)
             {
                 TraverseParticle(particleToProperties, baseType, typeInfo, ct.DerivedBy);
             }
             TraverseAttributes(ct.AttributeUses, baseType.AttributeUses, typeInfo);
         }
     }
     else
     {
         typeInfo.AddMember(BuildSimpleTypeTextProperty(parentElement, schemaType as XmlSchemaSimpleType));
     }
 }
예제 #10
0
        private void BuildProperties(XmlSchemaElement parentElement, XmlSchemaType schemaType, ClrContentTypeInfo typeInfo)
        {
            XmlSchemaComplexType ct = schemaType as XmlSchemaComplexType;

            if (ct != null)
            {
                if (ct.TypeCode == XmlTypeCode.Item)
                {
                    return;
                }
                XmlSchemaParticle    particleToProperties = ct.ContentTypeParticle;
                XmlSchemaComplexType baseType             = ct.BaseXmlSchemaType as XmlSchemaComplexType;
                if (schemaType.GetContentType() == XmlSchemaContentType.TextOnly)
                {
                    //Try to create a text property for the simple content
                    ClrPropertyInfo property = BuildComplexTypeTextProperty(parentElement, ct);
                    if (property != null)
                    {
                        typeInfo.AddMember(property);
                    }
                    if (baseType == null)
                    { //Derived from Simple type, first step simpleContent extension
                        TraverseAttributes(ct.AttributeUses, typeInfo);
                    }
                    else
                    {                                     //Derived from another complex type simple content, generate the content only if there are additional restrictions
                        if (!ct.IsDerivedByRestriction()) //process attributes only if not derived by restriction
                        {
                            TraverseAttributes(ct.AttributeUses, baseType.AttributeUses, typeInfo);
                        }
                    }
                }
                else
                {
                    Debug.Assert(baseType != null); //ComplexType with complexContent is always derived from another complexType
                    if (ct.IsDerivedByRestriction())
                    {                               //Do not handle restrictions on complex content?
                        return;
                    }
                    if (particleToProperties.GetParticleType() != ParticleType.Empty)
                    {
                        TraverseParticle(particleToProperties, baseType, typeInfo, ct.DerivedBy);
                    }
                    TraverseAttributes(ct.AttributeUses, baseType.AttributeUses, typeInfo);
                }
            }
            else
            {
                typeInfo.AddMember(BuildSimpleTypeTextProperty(parentElement, schemaType as XmlSchemaSimpleType));
            }
        }
        private void TraverseParticle(XmlSchemaParticle particle, XmlSchemaComplexType baseType, ClrContentTypeInfo typeInfo, XmlSchemaDerivationMethod derivationMethod)
        {
            if (this.particleStack != null)
            {
                this.particleStack.Clear();
            }
            else
            {
                this.particleStack = new Stack <XsdToTypesConverter.ParticleData>();
            }
            if (this.propertyNameTypeTable != null)
            {
                this.propertyNameTypeTable.Clear();
            }
            else
            {
                this.propertyNameTypeTable = new Dictionary <string, ClrPropertyInfo>();
            }
            XmlSchemaParticle  baseParticle        = baseType.ContentTypeParticle;
            GroupingInfo       parentGroupInfo     = null;
            StringBuilder      regEx               = new StringBuilder();
            XmlSchemaGroupBase currentGroupBase    = null;
            GroupingInfo       currentGroupingInfo = null;
            int currentIndex = 0;

            while (true)
            {
                if ((currentGroupBase == null ? true : currentIndex <= currentGroupBase.Items.Count))
                {
                    ParticleType particleType = particle.GetParticleType();
                    switch (particleType)
                    {
                    case ParticleType.Sequence:
                    case ParticleType.Choice:
                    case ParticleType.All:
                    {
                        regEx.Append("(");
                        if (currentGroupBase != null)
                        {
                            this.particleStack.Push(new XsdToTypesConverter.ParticleData(currentGroupBase, currentGroupingInfo, currentIndex));
                            currentIndex = 0;
                        }
                        parentGroupInfo  = currentGroupingInfo;
                        currentGroupBase = particle as XmlSchemaGroupBase;
                        Debug.Assert(currentGroupBase != null);
                        currentGroupingInfo = new GroupingInfo((ContentModelType)particleType, this.GetOccurence(currentGroupBase));
                        if (parentGroupInfo != null)
                        {
                            parentGroupInfo.AddChild(currentGroupingInfo);
                            parentGroupInfo.HasChildGroups = true;
                            currentGroupingInfo.IsNested   = true;
                            if (parentGroupInfo.IsRepeating)
                            {
                                currentGroupingInfo.IsRepeating = true;
                            }
                            if (currentGroupingInfo.IsRepeating)
                            {
                                parentGroupInfo.HasRepeatingGroups = true;
                            }
                        }
                        else
                        {
                            typeInfo.AddMember(currentGroupingInfo);
                            parentGroupInfo = currentGroupingInfo;
                        }
                        break;
                    }

                    case ParticleType.Element:
                    {
                        XmlSchemaElement elem         = particle as XmlSchemaElement;
                        ClrPropertyInfo  propertyInfo = null;
                        bool             fromBaseType = false;
                        if ((derivationMethod != XmlSchemaDerivationMethod.Extension ? false : typeInfo.IsDerived))
                        {
                            if (baseParticle.ContainsElement(elem))
                            {
                                fromBaseType = true;
                            }
                            else if ((typeInfo.InlineBaseType ? false : baseType.ContainsName(elem.QualifiedName)))
                            {
                                typeInfo.InlineBaseType = true;
                            }
                        }
                        propertyInfo = this.BuildProperty(elem, fromBaseType);
                        regEx.Append(propertyInfo.PropertyName);
                        this.AppendOccurenceToRegex(propertyInfo, regEx);
                        if (currentGroupingInfo != null)
                        {
                            this.BuildAnnotationInformation(propertyInfo, elem, currentGroupingInfo.ContentModelType == ContentModelType.Choice, currentGroupingInfo.IsNested);
                            currentGroupingInfo.AddChild(propertyInfo);
                            this.SetPropertyFlags(propertyInfo, currentGroupingInfo, elem.ElementSchemaType);
                        }
                        else
                        {
                            this.BuildAnnotationInformation(propertyInfo, elem, false, false);
                            typeInfo.AddMember(propertyInfo);
                        }
                        break;
                    }

                    case ParticleType.Any:
                    {
                        regEx.Append("any");
                        XmlSchemaAny any = particle as XmlSchemaAny;
                        if ((derivationMethod != XmlSchemaDerivationMethod.Extension ? false : typeInfo.IsDerived))
                        {
                            if (baseParticle.ContainsWildCard(any))
                            {
                                typeInfo.HasElementWildCard = true;
                            }
                        }
                        ClrWildCardPropertyInfo wcPropertyInfo = this.BuildAnyProperty(any, !typeInfo.HasElementWildCard);
                        if (currentGroupingInfo != null)
                        {
                            currentGroupingInfo.AddChild(wcPropertyInfo);
                        }
                        else
                        {
                            typeInfo.AddMember(wcPropertyInfo);
                        }
                        if (!typeInfo.HasElementWildCard)
                        {
                            typeInfo.HasElementWildCard = true;
                        }
                        break;
                    }
                    }
                }
                if ((currentGroupBase == null ? true : currentIndex >= currentGroupBase.Items.Count))
                {
                    if (currentGroupBase != null)
                    {
                        regEx.Append(")");
                        this.AppendOccurenceToRegex(currentGroupingInfo, regEx);
                    }
                    if (this.particleStack.Count <= 0)
                    {
                        break;
                    }
                    bool childGroupHasRecurringElements           = currentGroupingInfo.HasRecurrentElements;
                    bool childGroupHasRepeatingGroups             = currentGroupingInfo.HasRepeatingGroups;
                    XsdToTypesConverter.ParticleData particleData = this.particleStack.Pop();
                    currentGroupBase    = particleData.currentGroupBase;
                    currentGroupingInfo = particleData.currentGroupingInfo;
                    currentGroupingInfo.HasRecurrentElements = childGroupHasRecurringElements;
                    currentGroupingInfo.HasRepeatingGroups   = childGroupHasRepeatingGroups;
                    currentIndex = particleData.currentIndex;
                    if (currentIndex >= currentGroupBase.Items.Count)
                    {
                        currentIndex++;
                    }
                    else
                    {
                        int num = currentIndex;
                        currentIndex = num + 1;
                        particle     = (XmlSchemaParticle)currentGroupBase.Items[num];
                        regEx.Append((currentGroupingInfo.ContentModelType == ContentModelType.Choice ? "|" : ", "));
                    }
                }
                else
                {
                    if (currentIndex > 0)
                    {
                        regEx.Append((currentGroupingInfo.ContentModelType == ContentModelType.Choice ? " | " : ", "));
                    }
                    int num1 = currentIndex;
                    currentIndex = num1 + 1;
                    particle     = (XmlSchemaParticle)currentGroupBase.Items[num1];
                }
            }
            if (regEx.Length != 0)
            {
                typeInfo.ContentModelRegEx = regEx.ToString();
            }
        }
        private void TraverseAttributes(XmlSchemaObjectTable derivedAttributes, XmlSchemaObjectTable baseAttributes, ClrContentTypeInfo typeInfo)
        {
            ClrBasePropertyInfo propertyInfo;

            foreach (XmlSchemaAttribute derivedAttribute in derivedAttributes.Values)
            {
                if (derivedAttribute.Use != XmlSchemaUse.Prohibited)
                {
                    XmlSchemaAttribute baseAttribute = baseAttributes[derivedAttribute.QualifiedName] as XmlSchemaAttribute;
                    if ((baseAttribute == null ? true : baseAttribute != derivedAttribute))
                    {
                        propertyInfo = this.BuildProperty(derivedAttribute, false, baseAttribute != null);
                        this.BuildAnnotationInformation(propertyInfo, derivedAttribute, false, false);
                        typeInfo.AddMember(propertyInfo);
                    }
                    else
                    {
                        propertyInfo = this.BuildProperty(derivedAttribute, typeInfo.IsDerived, false);
                        this.BuildAnnotationInformation(propertyInfo, derivedAttribute, false, false);
                        typeInfo.AddMember(propertyInfo);
                    }
                }
            }
        }
        private void BuildProperties(XmlSchemaElement parentElement, XmlSchemaType schemaType, ClrContentTypeInfo typeInfo)
        {
            XmlSchemaComplexType ct = schemaType as XmlSchemaComplexType;

            if (ct == null)
            {
                typeInfo.AddMember(this.BuildSimpleTypeTextProperty(parentElement, schemaType as XmlSchemaSimpleType));
            }
            else if (ct.TypeCode != XmlTypeCode.Item)
            {
                XmlSchemaParticle    particleToProperties = ct.ContentTypeParticle;
                XmlSchemaComplexType baseType             = ct.BaseXmlSchemaType as XmlSchemaComplexType;
                if (schemaType.GetContentType() != XmlSchemaContentType.TextOnly)
                {
                    Debug.Assert(baseType != null);
                    if (ct.IsDerivedByRestriction())
                    {
                        return;
                    }
                    if (particleToProperties.GetParticleType() != ParticleType.Empty)
                    {
                        this.TraverseParticle(particleToProperties, baseType, typeInfo, ct.DerivedBy);
                    }
                    this.TraverseAttributes(ct.AttributeUses, baseType.AttributeUses, typeInfo);
                }
                else
                {
                    ClrPropertyInfo property = this.BuildComplexTypeTextProperty(parentElement, ct);
                    if (property != null)
                    {
                        typeInfo.AddMember(property);
                    }
                    if (baseType == null)
                    {
                        this.TraverseAttributes(ct.AttributeUses, typeInfo);
                    }
                    else if (!ct.IsDerivedByRestriction())
                    {
                        this.TraverseAttributes(ct.AttributeUses, baseType.AttributeUses, typeInfo);
                    }
                }
            }
        }
        private void BuildNestedTypes(ClrContentTypeInfo typeInfo)
        {
            ClrSimpleTypeInfo clrSimpleTypeInfo;

            foreach (AnonymousType at in this.localSymbolTable.GetAnonymousTypes())
            {
                XmlQualifiedName     qname       = null;
                XmlSchemaComplexType complexType = null;
                XmlSchemaElement     elem        = at.parentElement;
                if (elem != null)
                {
                    qname       = elem.QualifiedName;
                    complexType = elem.ElementSchemaType as XmlSchemaComplexType;
                }
                else
                {
                    complexType = at.wrappingType;
                    qname       = complexType.QualifiedName;
                }
                if (complexType != null)
                {
                    if ((complexType.GetContentType() != XmlSchemaContentType.TextOnly ? true : !complexType.IsDerivedByRestriction()))
                    {
                        ClrContentTypeInfo clrContentTypeInfo = new ClrContentTypeInfo();
                        this.localSymbolTable.Init(at.identifier);
                        clrContentTypeInfo.clrtypeName = at.identifier;
                        clrContentTypeInfo.clrtypeNs   = this.configSettings.GetClrNamespace(qname.Namespace);
                        clrContentTypeInfo.schemaName  = qname.Name;
                        clrContentTypeInfo.schemaNs    = qname.Namespace;
                        clrContentTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                        clrContentTypeInfo.IsNested    = true;
                        clrContentTypeInfo.baseType    = this.BaseType(complexType);
                        this.BuildProperties(elem, complexType, clrContentTypeInfo);
                        this.BuildNestedTypes(clrContentTypeInfo);
                        this.BuildAnnotationInformation(clrContentTypeInfo, complexType);
                        typeInfo.NestedTypes.Add(clrContentTypeInfo);
                    }
                    else
                    {
                        clrSimpleTypeInfo             = ClrSimpleTypeInfo.CreateSimpleTypeInfo(complexType);
                        clrSimpleTypeInfo.clrtypeName = at.identifier;
                        clrSimpleTypeInfo.clrtypeNs   = this.configSettings.GetClrNamespace(qname.Namespace);
                        clrSimpleTypeInfo.schemaName  = qname.Name;
                        clrSimpleTypeInfo.schemaNs    = qname.Namespace;
                        clrSimpleTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                        clrSimpleTypeInfo.IsNested    = true;
                        this.BuildAnnotationInformation(clrSimpleTypeInfo, complexType);
                        typeInfo.NestedTypes.Add(clrSimpleTypeInfo);
                    }
                }
                XmlSchemaSimpleType simpleType = null;
                if (elem != null)
                {
                    simpleType = elem.ElementSchemaType as XmlSchemaSimpleType;
                }
                if (simpleType != null)
                {
                    clrSimpleTypeInfo             = ClrSimpleTypeInfo.CreateSimpleTypeInfo(simpleType);
                    clrSimpleTypeInfo.clrtypeName = at.identifier;
                    clrSimpleTypeInfo.clrtypeNs   = this.configSettings.GetClrNamespace(qname.Namespace);
                    clrSimpleTypeInfo.schemaName  = qname.Name;
                    clrSimpleTypeInfo.schemaNs    = qname.Namespace;
                    clrSimpleTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                    clrSimpleTypeInfo.IsNested    = true;
                    this.BuildAnnotationInformation(clrSimpleTypeInfo, simpleType);
                    typeInfo.NestedTypes.Add(clrSimpleTypeInfo);
                }
            }
        }
예제 #15
0
        internal void TypeToType(XmlSchemaType st)
        {
            XmlSchemaSimpleType simpleType = st as XmlSchemaSimpleType;
            if (simpleType != null)
            {
                this.AddSimpleType(simpleType.QualifiedName, simpleType);
            }
            else
            {
                XmlSchemaComplexType ct = st as XmlSchemaComplexType;
                if (ct != null && ct.TypeCode != XmlTypeCode.Item)
                {
                    SymbolEntry symbol = symbolTable.AddType(ct.QualifiedName, ct);
                    string xsdNamespace = ct.QualifiedName.Namespace;

                    localSymbolTable.Init(symbol.identifierName);

                    ClrContentTypeInfo typeInfo = new ClrContentTypeInfo();
                    typeInfo.IsAbstract = ct.IsAbstract;
                    typeInfo.IsSealed = ct.IsFinal();
                    typeInfo.clrtypeName = symbol.identifierName;
                    typeInfo.clrtypeNs = symbol.clrNamespace;
                    typeInfo.schemaName = symbol.symbolName;
                    typeInfo.schemaNs = xsdNamespace;

                    typeInfo.typeOrigin = SchemaOrigin.Fragment;
                    typeInfo.baseType = BaseType(ct);
                    BuildProperties(null, ct, typeInfo);
                    BuildNestedTypes(typeInfo);
                    BuildAnnotationInformation(typeInfo, ct);
                    binding.Types.Add(typeInfo);
                }
            }
        }
예제 #16
0
        private void BuildNestedTypes(ClrContentTypeInfo typeInfo)
        {
            List<AnonymousType> anonymousTypes = localSymbolTable.GetAnonymousTypes();
            foreach (AnonymousType at in anonymousTypes)
            {

                XmlQualifiedName qname = null;
                XmlSchemaComplexType complexType = null;

                XmlSchemaElement elem = at.parentElement;
                if (elem == null)
                {//case 1: "dummy" type for text content in a complex type, with restrictions
                    complexType = at.wrappingType;
                    qname = complexType.QualifiedName;
                }
                else
                {//case 2: anonymous type can also be nested under an element
                    qname = elem.QualifiedName;
                    complexType = elem.ElementSchemaType as XmlSchemaComplexType;
                }
                if (complexType != null)
                {
                    if (complexType.GetContentType() == XmlSchemaContentType.TextOnly
                        && complexType.IsDerivedByRestriction())
                    {
                        //In this case, we take care of the content/text part only. No nesting types exist.
                        ClrSimpleTypeInfo nestedTypeInfo = ClrSimpleTypeInfo.CreateSimpleTypeInfo(complexType);//Generate its "simple type" version to save restrictions
                        nestedTypeInfo.clrtypeName = at.identifier;
                        nestedTypeInfo.clrtypeNs = configSettings.GetClrNamespace(qname.Namespace);
                        nestedTypeInfo.schemaName = qname.Name;
                        nestedTypeInfo.schemaNs = qname.Namespace;
                        nestedTypeInfo.typeOrigin = SchemaOrigin.Fragment;
                        nestedTypeInfo.IsNested = true;
                        BuildAnnotationInformation(nestedTypeInfo, complexType);
                        typeInfo.NestedTypes.Add(nestedTypeInfo);
                    }
                    else
                    {
                        ClrContentTypeInfo nestedTypeInfo = new ClrContentTypeInfo();
                        localSymbolTable.Init(at.identifier);
                        nestedTypeInfo.clrtypeName = at.identifier;
                        nestedTypeInfo.clrtypeNs = configSettings.GetClrNamespace(qname.Namespace);
                        nestedTypeInfo.schemaName = qname.Name;
                        nestedTypeInfo.schemaNs = qname.Namespace;
                        nestedTypeInfo.typeOrigin = SchemaOrigin.Fragment;
                        nestedTypeInfo.IsNested = true;
                        nestedTypeInfo.baseType = BaseType(complexType);
                        BuildProperties(elem, complexType, nestedTypeInfo);
                        BuildNestedTypes(nestedTypeInfo);
                        BuildAnnotationInformation(nestedTypeInfo, complexType);
                        typeInfo.NestedTypes.Add(nestedTypeInfo);
                    }
                }

                //Also handle simple types
                XmlSchemaSimpleType simpleType = null;
                if (elem != null) simpleType = elem.ElementSchemaType as XmlSchemaSimpleType;

                if (simpleType != null)
                {
                    ClrSimpleTypeInfo nestedTypeInfo = ClrSimpleTypeInfo.CreateSimpleTypeInfo(simpleType);
                    nestedTypeInfo.clrtypeName = at.identifier;
                    nestedTypeInfo.clrtypeNs = configSettings.GetClrNamespace(qname.Namespace);
                    nestedTypeInfo.schemaName = qname.Name;
                    nestedTypeInfo.schemaNs = qname.Namespace;
                    nestedTypeInfo.typeOrigin = SchemaOrigin.Fragment;
                    nestedTypeInfo.IsNested = true;
                    BuildAnnotationInformation(nestedTypeInfo, simpleType);
                    typeInfo.NestedTypes.Add(nestedTypeInfo);
                }
            }
        }
예제 #17
0
 private void TraverseAttributes(XmlSchemaObjectTable derivedAttributes, XmlSchemaObjectTable baseAttributes, ClrContentTypeInfo typeInfo)
 {
     foreach (XmlSchemaAttribute derivedAttribute in derivedAttributes.Values)
     {
         if (derivedAttribute.Use == XmlSchemaUse.Prohibited)
         {
             continue;
         }
         XmlSchemaAttribute baseAttribute = baseAttributes[derivedAttribute.QualifiedName] as XmlSchemaAttribute;
         if (baseAttribute != null && baseAttribute == derivedAttribute)
         {
             // Its the one copied from the base
             // http://linqtoxsd.codeplex.com/WorkItem/View.aspx?WorkItemId=3064
             ClrBasePropertyInfo propertyInfo = BuildProperty(
                 derivedAttribute, typeInfo.IsDerived, false);
             BuildAnnotationInformation(propertyInfo, derivedAttribute, false, false);
             typeInfo.AddMember(propertyInfo);
         }
         else
         {
             ClrBasePropertyInfo propertyInfo = BuildProperty(derivedAttribute, false, baseAttribute != null);
             BuildAnnotationInformation(propertyInfo, derivedAttribute, false, false);
             typeInfo.AddMember(propertyInfo);
         }
     }
 }
예제 #18
0
 private void TraverseAttributes(XmlSchemaObjectTable derivedAttributes, ClrContentTypeInfo typeInfo)
 {
     foreach (XmlSchemaAttribute derivedAttribute in derivedAttributes.Values)
     {
         Debug.Assert(derivedAttribute.AttributeSchemaType != null); //For use=prohibited, without derivation it doesnt mean anything, hence attribute should be compiled
         ClrBasePropertyInfo propertyInfo = BuildProperty(derivedAttribute, false, false);
         BuildAnnotationInformation(propertyInfo, derivedAttribute, false, false);
         typeInfo.AddMember(propertyInfo);
     }
 }
        internal void ElementsToTypes()
        {
            bool isRoot            = false;
            int  rootElementsCount = schemas.GlobalElements.Count;

            foreach (XmlSchemaElement elem in schemas.GlobalElements.Values)
            {
                SymbolEntry   symbol       = symbolTable.AddElement(elem);
                XmlSchemaType schemaType   = elem.ElementSchemaType;
                string        xsdNamespace = elem.QualifiedName.Namespace;

                ClrTypeInfo      typeInfo    = null;
                XmlSchemaElement headElement = null;
                if (!elem.SubstitutionGroup.IsEmpty)
                {
                    headElement = (XmlSchemaElement)schemas.GlobalElements[elem.SubstitutionGroup];
                }

                if (schemaType.IsGlobal())
                {
                    //Global elem with global type, generate wrapper class for the element
                    bool hasBaseContentType      = headElement != null && headElement.ElementSchemaType == schemaType;
                    ClrWrapperTypeInfo wtypeInfo = new ClrWrapperTypeInfo(hasBaseContentType);
                    ClrTypeReference   typeDef   = BuildTypeReference(schemaType, schemaType.QualifiedName, false, true);
                    //Save the fixed/default value of the element
                    wtypeInfo.InnerType = typeDef;
                    typeInfo            = wtypeInfo;
                    typeInfo.baseType   =
                        headElement; //If element is member of substitutionGroup, add derivation step
                }
                else
                {
                    ClrContentTypeInfo ctypeInfo = new ClrContentTypeInfo();
                    localSymbolTable.Init(symbol.identifierName);
                    ctypeInfo.baseType =
                        headElement; //If element is member of substitutionGroup, add derivation step
                    BuildProperties(elem, schemaType, ctypeInfo);
                    BuildNestedTypes(ctypeInfo);
                    typeInfo = ctypeInfo;
                }

                if (!isRoot)
                {
                    if (rootElementsCount == 1 || CheckUnhandledAttributes(elem))
                    {
                        typeInfo.IsRoot = true;
                        isRoot          = true;
                    }
                }

                typeInfo.IsSubstitutionHead = IsSubstitutionGroupHead(elem) != null;
                typeInfo.IsAbstract         = elem.IsAbstract;
                typeInfo.clrtypeName        = symbol.identifierName;
                typeInfo.clrtypeNs          = symbol.clrNamespace;
                typeInfo.schemaName         = symbol.symbolName;
                typeInfo.schemaNs           = xsdNamespace;

                typeInfo.typeOrigin = SchemaOrigin.Element;

                BuildAnnotationInformation(typeInfo, schemaType);
                binding.Types.Add(typeInfo);
            }
        }
예제 #20
0
        private void TraverseParticle(XmlSchemaParticle particle, XmlSchemaComplexType baseType, ClrContentTypeInfo typeInfo, XmlSchemaDerivationMethod derivationMethod)
        {
            if (particleStack == null)
            {
                particleStack = new Stack<ParticleData>();
            }
            else
            {
                particleStack.Clear();
            }
            if (propertyNameTypeTable == null)
            {
                propertyNameTypeTable = new Dictionary<string, ClrPropertyInfo>();
            }
            else
            {
                propertyNameTypeTable.Clear();
            }

            XmlSchemaParticle baseParticle = baseType.ContentTypeParticle;
            ParticleData particleData;
            GroupingInfo parentGroupInfo = null;
            StringBuilder regEx = new StringBuilder();

            XmlSchemaGroupBase currentGroupBase = null;
            GroupingInfo currentGroupingInfo = null;

            int currentIndex = 0;

            while (true)
            {

                // dont interrogate a particle if we are past the end of the list
                if (currentGroupBase == null || currentIndex <= currentGroupBase.Items.Count)
                {
                    ParticleType particleType = particle.GetParticleType();
                    switch (particleType)
                    {
                        case ParticleType.Element:
                            {
                                XmlSchemaElement elem = particle as XmlSchemaElement;
                                ClrPropertyInfo propertyInfo = null;
                                bool fromBaseType = false;
                                if (derivationMethod == XmlSchemaDerivationMethod.Extension && typeInfo.IsDerived)
                                {
                                    if (baseParticle.ContainsElement(elem))
                                    {
                                        fromBaseType = true;
                                    }
                                    else if (!typeInfo.InlineBaseType && baseType.ContainsName(elem.QualifiedName))
                                    {
                                        typeInfo.InlineBaseType = true;
                                    }

                                }
                                propertyInfo = BuildProperty(elem, fromBaseType);
                                regEx.Append(propertyInfo.PropertyName);
                                AppendOccurenceToRegex(propertyInfo, regEx);
                                //Add to parent
                                if (currentGroupingInfo == null)
                                {
                                    //Not adding property to propertyNameTypeTable as this case will occur only for pointless groups, so they have just one property
                                    BuildAnnotationInformation(propertyInfo, elem, false, false);
                                    typeInfo.AddMember(propertyInfo);
                                }
                                else
                                {
                                    BuildAnnotationInformation(propertyInfo, elem, currentGroupingInfo.ContentModelType == ContentModelType.Choice, currentGroupingInfo.IsNested);
                                    currentGroupingInfo.AddChild(propertyInfo);
                                    SetPropertyFlags(propertyInfo, currentGroupingInfo, elem.ElementSchemaType);
                                }
                                break;

                            }
                        case ParticleType.Any:
                            {
                                regEx.Append("any");
                                XmlSchemaAny any = particle as XmlSchemaAny;

                                if (derivationMethod == XmlSchemaDerivationMethod.Extension && typeInfo.IsDerived)
                                {
                                    if (baseParticle.ContainsWildCard(any))
                                    {
                                        typeInfo.HasElementWildCard = true;//ANY property in the base type will be reused
                                    }
                                }

                                //Note we always create a property info object to keep the original nesting structure in the schema
                                //so it can be used to create a correct FSM; on the other hand, typeInfo.HasElementWildCard will indicate whether
                                //we need to create a property in the resulting object type.
                                ClrWildCardPropertyInfo wcPropertyInfo = BuildAnyProperty(any, !typeInfo.HasElementWildCard);

                                //Add to parent
                                if (currentGroupingInfo == null)
                                {
                                    typeInfo.AddMember(wcPropertyInfo);
                                }
                                else
                                {
                                    currentGroupingInfo.AddChild(wcPropertyInfo);
                                }
                                if (!typeInfo.HasElementWildCard) typeInfo.HasElementWildCard = true;
                                break;
                            }

                        case ParticleType.Sequence:
                        case ParticleType.Choice:
                        case ParticleType.All:
                            regEx.Append("(");
                            if (currentGroupBase != null)
                            {
                                //already there is a group that we are processing, push it on stack to process sub-group
                                particleStack.Push(new ParticleData(currentGroupBase, currentGroupingInfo, currentIndex));
                                currentIndex = 0; //Re-start index for new group base
                            }
                            parentGroupInfo = currentGroupingInfo; //Assign parent before creating child groupInfo
                            currentGroupBase = particle as XmlSchemaGroupBase;
                            Debug.Assert(currentGroupBase != null);
                            currentGroupingInfo = new GroupingInfo((ContentModelType)((int)particleType), GetOccurence(currentGroupBase));

                            //Add to parent
                            if (parentGroupInfo == null)
                            {
                                typeInfo.AddMember(currentGroupingInfo);
                                parentGroupInfo = currentGroupingInfo; //Assign first time
                            }
                            else
                            {
                                parentGroupInfo.AddChild(currentGroupingInfo);
                                parentGroupInfo.HasChildGroups = true;
                                currentGroupingInfo.IsNested = true;
                                if (parentGroupInfo.IsRepeating)
                                {
                                    currentGroupingInfo.IsRepeating = true;
                                }
                                if (currentGroupingInfo.IsRepeating)
                                {
                                    parentGroupInfo.HasRepeatingGroups = true;
                                }
                            }
                            break;

                    }
                }
                //Drill down into items
                if (currentGroupBase != null && currentIndex < currentGroupBase.Items.Count)
                {
                    // if this isnt the first, then we need a seperator
                    if (currentIndex > 0)
                    {
                        regEx.Append(currentGroupingInfo.ContentModelType == ContentModelType.Choice ? " | " : ", ");
                    }
                    particle = (XmlSchemaParticle)currentGroupBase.Items[currentIndex++];
                }
                else
                {
                    if (currentGroupBase != null)
                    {
                        regEx.Append(")");
                        AppendOccurenceToRegex(currentGroupingInfo, regEx);
                    }

                    if (particleStack.Count > 0)
                    {
                        bool childGroupHasRecurringElements = currentGroupingInfo.HasRecurrentElements;
                        bool childGroupHasRepeatingGroups = currentGroupingInfo.HasRepeatingGroups;

                        particleData = particleStack.Pop();
                        currentGroupBase = particleData.currentGroupBase;
                        currentGroupingInfo = particleData.currentGroupingInfo;

                        currentGroupingInfo.HasRecurrentElements = childGroupHasRecurringElements;
                        currentGroupingInfo.HasRepeatingGroups = childGroupHasRepeatingGroups;

                        currentIndex = particleData.currentIndex;
                        if (currentIndex < currentGroupBase.Items.Count)
                        {
                            particle = (XmlSchemaParticle)currentGroupBase.Items[currentIndex++];
                            regEx.Append(currentGroupingInfo.ContentModelType == ContentModelType.Choice ? "|" : ", ");
                        }
                        else
                        {
                            // we were already at the end of the parent group, so just continue
                            currentIndex++; //we are off the end of this list
                        }
                    }
                    else
                    { //No more particles to process
                        break;
                    }
                }
            }
            if (regEx.Length != 0)
            {
                typeInfo.ContentModelRegEx = regEx.ToString();
            }
        }
        private void BuildNestedTypes(ClrContentTypeInfo typeInfo)
        {
            List <AnonymousType> anonymousTypes = localSymbolTable.GetAnonymousTypes();

            foreach (AnonymousType at in anonymousTypes)
            {
                XmlQualifiedName     qname       = null;
                XmlSchemaComplexType complexType = null;

                XmlSchemaElement elem = at.parentElement;
                if (elem == null)
                {
                    //case 1: "dummy" type for text content in a complex type, with restrictions
                    complexType = at.wrappingType;
                    qname       = complexType.QualifiedName;
                }
                else
                {
                    //case 2: anonymous type can also be nested under an element
                    qname       = elem.QualifiedName;
                    complexType = elem.ElementSchemaType as XmlSchemaComplexType;
                }

                if (complexType != null)
                {
                    if (complexType.GetContentType() == XmlSchemaContentType.TextOnly &&
                        complexType.IsDerivedByRestriction())
                    {
                        //In this case, we take care of the content/text part only. No nesting types exist.
                        ClrSimpleTypeInfo
                            nestedTypeInfo =
                            ClrSimpleTypeInfo
                            .CreateSimpleTypeInfo(
                                complexType);         //Generate its "simple type" version to save restrictions
                        nestedTypeInfo.clrtypeName = at.identifier;
                        nestedTypeInfo.clrtypeNs   = configSettings.GetClrNamespace(qname.Namespace);
                        nestedTypeInfo.schemaName  = qname.Name;
                        nestedTypeInfo.schemaNs    = qname.Namespace;
                        nestedTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                        nestedTypeInfo.IsNested    = true;
                        BuildAnnotationInformation(nestedTypeInfo, complexType);
                        typeInfo.NestedTypes.Add(nestedTypeInfo);
                    }
                    else
                    {
                        ClrContentTypeInfo nestedTypeInfo = new ClrContentTypeInfo()
                        {
                            Parent = typeInfo
                        };
                        localSymbolTable.Init(at.identifier);
                        nestedTypeInfo.clrtypeName = at.identifier;
                        nestedTypeInfo.clrtypeNs   = configSettings.GetClrNamespace(qname.Namespace);
                        nestedTypeInfo.schemaName  = qname.Name;
                        nestedTypeInfo.schemaNs    = qname.Namespace;
                        nestedTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                        nestedTypeInfo.IsNested    = true;
                        nestedTypeInfo.baseType    = BaseType(complexType);
                        BuildProperties(elem, complexType, nestedTypeInfo);
                        BuildNestedTypes(nestedTypeInfo);
                        BuildAnnotationInformation(nestedTypeInfo, complexType);
                        typeInfo.NestedTypes.Add(nestedTypeInfo);
                    }
                }

                //Also handle simple types
                XmlSchemaSimpleType simpleType = null;
                if (elem != null)
                {
                    simpleType = elem.ElementSchemaType as XmlSchemaSimpleType;
                }

                if (simpleType != null)
                {
                    ClrSimpleTypeInfo nestedTypeInfo = ClrSimpleTypeInfo.CreateSimpleTypeInfo(simpleType);
                    nestedTypeInfo.clrtypeName = at.identifier;
                    nestedTypeInfo.clrtypeNs   = configSettings.GetClrNamespace(qname.Namespace);
                    nestedTypeInfo.schemaName  = qname.Name;
                    nestedTypeInfo.schemaNs    = qname.Namespace;
                    nestedTypeInfo.typeOrigin  = SchemaOrigin.Fragment;
                    nestedTypeInfo.IsNested    = true;
                    BuildAnnotationInformation(nestedTypeInfo, simpleType);
                    typeInfo.NestedTypes.Add(nestedTypeInfo);
                }
            }
        }