Exemple #1
0
        internal XmlSchemaObject Clone(XmlSchema parentSchema)
        {
            XmlSchemaComplexType complexType = (XmlSchemaComplexType)MemberwiseClone();

            //Deep clone the QNames as these will be updated on chameleon includes
            if (complexType.ContentModel != null)   //simpleContent or complexContent

            {
                XmlSchemaSimpleContent simpleContent = complexType.ContentModel as XmlSchemaSimpleContent;
                if (simpleContent != null)
                {
                    XmlSchemaSimpleContent newSimpleContent = (XmlSchemaSimpleContent)simpleContent.Clone();

                    XmlSchemaSimpleContentExtension simpleExt = simpleContent.Content as XmlSchemaSimpleContentExtension;
                    if (simpleExt != null)
                    {
                        XmlSchemaSimpleContentExtension newSimpleExt = (XmlSchemaSimpleContentExtension)simpleExt.Clone();
                        newSimpleExt.BaseTypeName = simpleExt.BaseTypeName.Clone();
                        newSimpleExt.SetAttributes(CloneAttributes(simpleExt.Attributes));
                        newSimpleContent.Content = newSimpleExt;
                    }
                    else   //simpleContent.Content is XmlSchemaSimpleContentRestriction
                    {
                        XmlSchemaSimpleContentRestriction simpleRest    = (XmlSchemaSimpleContentRestriction)simpleContent.Content;
                        XmlSchemaSimpleContentRestriction newSimpleRest = (XmlSchemaSimpleContentRestriction)simpleRest.Clone();
                        newSimpleRest.BaseTypeName = simpleRest.BaseTypeName.Clone();
                        newSimpleRest.SetAttributes(CloneAttributes(simpleRest.Attributes));
                        newSimpleContent.Content = newSimpleRest;
                    }

                    complexType.ContentModel = newSimpleContent;
                }
                else   // complexType.ContentModel is XmlSchemaComplexContent
                {
                    XmlSchemaComplexContent complexContent    = (XmlSchemaComplexContent)complexType.ContentModel;
                    XmlSchemaComplexContent newComplexContent = (XmlSchemaComplexContent)complexContent.Clone();

                    XmlSchemaComplexContentExtension complexExt = complexContent.Content as XmlSchemaComplexContentExtension;
                    if (complexExt != null)
                    {
                        XmlSchemaComplexContentExtension newComplexExt = (XmlSchemaComplexContentExtension)complexExt.Clone();
                        newComplexExt.BaseTypeName = complexExt.BaseTypeName.Clone();
                        newComplexExt.SetAttributes(CloneAttributes(complexExt.Attributes));
                        if (HasParticleRef(complexExt.Particle, parentSchema))
                        {
                            newComplexExt.Particle = CloneParticle(complexExt.Particle, parentSchema);
                        }
                        newComplexContent.Content = newComplexExt;
                    }
                    else   // complexContent.Content is XmlSchemaComplexContentRestriction
                    {
                        XmlSchemaComplexContentRestriction complexRest    = complexContent.Content as XmlSchemaComplexContentRestriction;
                        XmlSchemaComplexContentRestriction newComplexRest = (XmlSchemaComplexContentRestriction)complexRest.Clone();
                        newComplexRest.BaseTypeName = complexRest.BaseTypeName.Clone();
                        newComplexRest.SetAttributes(CloneAttributes(complexRest.Attributes));
                        if (HasParticleRef(newComplexRest.Particle, parentSchema))
                        {
                            newComplexRest.Particle = CloneParticle(newComplexRest.Particle, parentSchema);
                        }
                        newComplexContent.Content = newComplexRest;
                    }
                    complexType.ContentModel = newComplexContent;
                }
            }
            else   //equals XmlSchemaComplexContent with baseType is anyType
            {
                if (HasParticleRef(complexType.Particle, parentSchema))
                {
                    complexType.Particle = CloneParticle(complexType.Particle, parentSchema);
                }
                complexType.SetAttributes(CloneAttributes(complexType.Attributes));
            }
            complexType.ClearCompiledState();
            return(complexType);
        }
 internal XmlSchemaObject Clone(XmlSchema parentSchema)
 {
     XmlSchemaComplexType type = (XmlSchemaComplexType) base.MemberwiseClone();
     if (type.ContentModel != null)
     {
         XmlSchemaSimpleContent contentModel = type.ContentModel as XmlSchemaSimpleContent;
         if (contentModel != null)
         {
             XmlSchemaSimpleContent content2 = (XmlSchemaSimpleContent) contentModel.Clone();
             XmlSchemaSimpleContentExtension content = contentModel.Content as XmlSchemaSimpleContentExtension;
             if (content != null)
             {
                 XmlSchemaSimpleContentExtension extension2 = (XmlSchemaSimpleContentExtension) content.Clone();
                 extension2.BaseTypeName = content.BaseTypeName.Clone();
                 extension2.SetAttributes(CloneAttributes(content.Attributes));
                 content2.Content = extension2;
             }
             else
             {
                 XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction) contentModel.Content;
                 XmlSchemaSimpleContentRestriction restriction2 = (XmlSchemaSimpleContentRestriction) restriction.Clone();
                 restriction2.BaseTypeName = restriction.BaseTypeName.Clone();
                 restriction2.SetAttributes(CloneAttributes(restriction.Attributes));
                 content2.Content = restriction2;
             }
             type.ContentModel = content2;
         }
         else
         {
             XmlSchemaComplexContent content3 = (XmlSchemaComplexContent) type.ContentModel;
             XmlSchemaComplexContent content4 = (XmlSchemaComplexContent) content3.Clone();
             XmlSchemaComplexContentExtension extension3 = content3.Content as XmlSchemaComplexContentExtension;
             if (extension3 != null)
             {
                 XmlSchemaComplexContentExtension extension4 = (XmlSchemaComplexContentExtension) extension3.Clone();
                 extension4.BaseTypeName = extension3.BaseTypeName.Clone();
                 extension4.SetAttributes(CloneAttributes(extension3.Attributes));
                 if (HasParticleRef(extension3.Particle, parentSchema))
                 {
                     extension4.Particle = CloneParticle(extension3.Particle, parentSchema);
                 }
                 content4.Content = extension4;
             }
             else
             {
                 XmlSchemaComplexContentRestriction restriction3 = content3.Content as XmlSchemaComplexContentRestriction;
                 XmlSchemaComplexContentRestriction restriction4 = (XmlSchemaComplexContentRestriction) restriction3.Clone();
                 restriction4.BaseTypeName = restriction3.BaseTypeName.Clone();
                 restriction4.SetAttributes(CloneAttributes(restriction3.Attributes));
                 if (HasParticleRef(restriction4.Particle, parentSchema))
                 {
                     restriction4.Particle = CloneParticle(restriction4.Particle, parentSchema);
                 }
                 content4.Content = restriction4;
             }
             type.ContentModel = content4;
         }
     }
     else
     {
         if (HasParticleRef(type.Particle, parentSchema))
         {
             type.Particle = CloneParticle(type.Particle, parentSchema);
         }
         type.SetAttributes(CloneAttributes(type.Attributes));
     }
     type.ClearCompiledState();
     return type;
 }