System.Xml.Schema.XmlSchemaComplexType.Clone C# (CSharp) Méthode

Clone() private méthode

private Clone ( ) : XmlSchemaObject
Résultat XmlSchemaObject
        internal override XmlSchemaObject Clone() {
            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)) {
                            newComplexExt.Particle = CloneParticle(complexExt.Particle);
                        }
                        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)) {
                            newComplexRest.Particle = CloneParticle(newComplexRest.Particle);
                        }
                        newComplexContent.Content = newComplexRest;
                    }
                    complexType.ContentModel = newComplexContent;
                }
            }
            else { //equals XmlSchemaComplexContent with baseType is anyType
                if (HasParticleRef(complexType.Particle)) {
                    complexType.Particle = CloneParticle(complexType.Particle);
                }
                complexType.SetAttributes(CloneAttributes(complexType.Attributes));
            }
            complexType.ClearCompiledState();
            return complexType;
        }

Usage Example

        internal XmlSchema DeepClone()
        {
            XmlSchema schema = new XmlSchema {
                attributeFormDefault = this.attributeFormDefault,
                elementFormDefault   = this.elementFormDefault,
                blockDefault         = this.blockDefault,
                finalDefault         = this.finalDefault,
                targetNs             = this.targetNs,
                version        = this.version,
                isPreprocessed = this.isPreprocessed
            };

            for (int i = 0; i < this.items.Count; i++)
            {
                XmlSchemaObject      obj2;
                XmlSchemaComplexType type = this.items[i] as XmlSchemaComplexType;
                if (type != null)
                {
                    obj2 = type.Clone(this);
                }
                else
                {
                    XmlSchemaElement element = this.items[i] as XmlSchemaElement;
                    if (element != null)
                    {
                        obj2 = element.Clone(this);
                    }
                    else
                    {
                        XmlSchemaGroup group = this.items[i] as XmlSchemaGroup;
                        if (group != null)
                        {
                            obj2 = group.Clone(this);
                        }
                        else
                        {
                            obj2 = this.items[i].Clone();
                        }
                    }
                }
                schema.Items.Add(obj2);
            }
            for (int j = 0; j < this.includes.Count; j++)
            {
                XmlSchemaExternal item = (XmlSchemaExternal)this.includes[j].Clone();
                schema.Includes.Add(item);
            }
            schema.Namespaces = base.Namespaces;
            schema.BaseUri    = this.BaseUri;
            return(schema);
        }
All Usage Examples Of System.Xml.Schema.XmlSchemaComplexType::Clone