Clone() private method

private Clone ( ) : XmlSchemaObject
return XmlSchemaObject
        internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle)
        {
            XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase;

            if (groupBase != null && !(groupBase is XmlSchemaAll))    //Choice or sequence
            {
                XmlSchemaGroupBase newGroupBase = groupBase;

                XmlSchemaObjectCollection newGroupbaseParticles = CloneGroupBaseParticles(groupBase.Items);
                newGroupBase = (XmlSchemaGroupBase)groupBase.Clone();
                newGroupBase.SetItems(newGroupbaseParticles);
                return(newGroupBase);
            }
            else if (particle is XmlSchemaGroupRef)   // group ref
            {
                XmlSchemaGroupRef newGroupRef = (XmlSchemaGroupRef)particle.Clone();
                newGroupRef.RefName = newGroupRef.RefName.Clone();
                return(newGroupRef);
            }
            else
            {
                XmlSchemaElement oldElem = particle as XmlSchemaElement;
                if (oldElem != null && (!oldElem.RefName.IsEmpty || !oldElem.SchemaTypeName.IsEmpty))   //Its element ref or type name is present
                {
                    XmlSchemaElement newElem = (XmlSchemaElement)oldElem.Clone();
                    return(newElem);
                }
            }
            return(particle);
        }
        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);
        }
Example #3
0
        internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle, XmlSchema parentSchema)
        {
            XmlSchemaGroupBase groupBase = particle as XmlSchemaGroupBase;

            if (groupBase != null)   //Choice or sequence
            {
                XmlSchemaGroupBase newGroupBase = groupBase;

                XmlSchemaObjectCollection newGroupbaseParticles = CloneGroupBaseParticles(groupBase.Items, parentSchema);
                newGroupBase = (XmlSchemaGroupBase)groupBase.Clone();
                newGroupBase.SetItems(newGroupbaseParticles);
                return(newGroupBase);
            }
            else if (particle is XmlSchemaGroupRef)   // group ref
            {
                XmlSchemaGroupRef newGroupRef = (XmlSchemaGroupRef)particle.Clone();
                newGroupRef.RefName = newGroupRef.RefName.Clone();
                return(newGroupRef);
            }
            else
            {
                XmlSchemaElement oldElem = particle as XmlSchemaElement;
                // If the particle is an element and one of the following is true:
                //   - it references another element by name
                //   - it references its type by name
                //   - it's form (effective) is qualified (meaning it will inherint namespace from chameleon includes if that happens)
                // then the element itself needs to be cloned.
                if (oldElem != null && (!oldElem.RefName.IsEmpty || !oldElem.SchemaTypeName.IsEmpty ||
                                        GetResolvedElementForm(parentSchema, oldElem) == XmlSchemaForm.Qualified))
                {
                    XmlSchemaElement newElem = (XmlSchemaElement)oldElem.Clone(parentSchema);
                    return(newElem);
                }
            }
            return(particle);
        }
 internal static XmlSchemaParticle CloneParticle(XmlSchemaParticle particle, XmlSchema parentSchema)
 {
     XmlSchemaGroupBase base2 = particle as XmlSchemaGroupBase;
     if (base2 != null)
     {
         XmlSchemaGroupBase base3 = base2;
         XmlSchemaObjectCollection newItems = CloneGroupBaseParticles(base2.Items, parentSchema);
         base3 = (XmlSchemaGroupBase) base2.Clone();
         base3.SetItems(newItems);
         return base3;
     }
     if (particle is XmlSchemaGroupRef)
     {
         XmlSchemaGroupRef ref2 = (XmlSchemaGroupRef) particle.Clone();
         ref2.RefName = ref2.RefName.Clone();
         return ref2;
     }
     XmlSchemaElement element = particle as XmlSchemaElement;
     if ((element == null) || ((element.RefName.IsEmpty && element.SchemaTypeName.IsEmpty) && (GetResolvedElementForm(parentSchema, element) != XmlSchemaForm.Qualified)))
     {
         return particle;
     }
     return (XmlSchemaElement) element.Clone(parentSchema);
 }