Clone() private method

private Clone ( ) : XmlSchemaObject
return XmlSchemaObject
        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);
        }
        internal XmlSchemaObject Clone(XmlSchema parentSchema)
        {
            XmlSchemaElement element = (XmlSchemaElement)base.MemberwiseClone();

            element.refName           = this.refName.Clone();
            element.substitutionGroup = this.substitutionGroup.Clone();
            element.typeName          = this.typeName.Clone();
            element.qualifiedName     = this.qualifiedName.Clone();
            XmlSchemaComplexType type = this.type as XmlSchemaComplexType;

            if ((type != null) && type.QualifiedName.IsEmpty)
            {
                element.type = (XmlSchemaType)type.Clone(parentSchema);
            }
            element.constraints = null;
            return(element);
        }
        internal XmlSchemaObject Clone(XmlSchema parentSchema)
        {
            XmlSchemaElement newElem = (XmlSchemaElement)MemberwiseClone();

            //Deep clone the QNames as these will be updated on chameleon includes
            newElem.refName           = this.refName.Clone();
            newElem.substitutionGroup = this.substitutionGroup.Clone();
            newElem.typeName          = this.typeName.Clone();
            newElem.qualifiedName     = this.qualifiedName.Clone();
            // If this element has a complex type which is anonymous (declared in place with the element)
            //  it needs to be cloned as well, since it may contain named elements and such. And these names
            //  will need to be cloned since they may change their namespace on chameleon includes
            XmlSchemaComplexType complexType = this.type as XmlSchemaComplexType;

            if (complexType != null && complexType.QualifiedName.IsEmpty)
            {
                newElem.type = (XmlSchemaType)complexType.Clone(parentSchema);
            }

            //Clear compiled tables
            newElem.constraints = null;
            return(newElem);
        }