예제 #1
0
        /// <summary>
        /// Initializes an element within the schema.
        /// </summary>
        /// <remarks>Detects if the element is recurring. If so, does not continue.</remarks>
        /// <param name="parent">The parent schema object that the new schemaobject (derived from the element parameter) should be attached to.</param>
        /// <param name="element">The XSD element that the new schema object should be created based on.</param>
        /// <returns>The newly created schema object, which is already attached as a child to the parent (or the document as a whole if no parent is specified)</returns>
        protected SchemaObject InitializeElement(SchemaObject parent, XmlSchemaElement element, bool update = false)
        {
            List <SchemaObject> siblings = parent == null ? this.Children : parent.Children;

            SchemaObject newSimpleObject = new SchemaObject(this, element)
            {
                Parent   = parent,
                Name     = this.GetName(element.QualifiedName, element.RefName),
                DataType = element.ElementSchemaType != null && !string.IsNullOrEmpty(element.ElementSchemaType.Name) ?
                           this.GetName(element.ElementSchemaType.QualifiedName, null) :
                           null,
                Type = ObjectTypes.Element
            };

            // Make sure the element doesn't already exist
            var foundExisting = siblings.SingleOrDefault(y => y.Name == newSimpleObject.Name);

            if (update && foundExisting != null)
            {
                var foundExistingIndex = siblings.IndexOf(foundExisting);
                siblings.Remove(foundExisting);
                siblings.Insert(foundExistingIndex, newSimpleObject);
            }
            else
            {
                siblings.Add(newSimpleObject);
            }

            if (this.initializing && newSimpleObject.Depth <= maxInitialDepth)
            {
                newSimpleObject.InitializeChildren(newSimpleObject, element);
            }

            return(newSimpleObject);
        }
예제 #2
0
        /// <summary>
        /// Creates a new SchemaObject as ObjectTypes.ComplexType
        /// </summary>
        /// <param name="complexType">The XSD complext ype that the new SchemaObject should be based on</param>
        private SchemaObject InitializeComplexType(XmlSchemaComplexType complexType)
        {
            SchemaObject newSimpleObject = new SchemaObject(this, complexType)
            {
                Name     = this.GetName(complexType.QualifiedName, null),
                DataType = complexType.BaseXmlSchemaType != null && !string.IsNullOrEmpty(complexType.BaseXmlSchemaType.Name) ?
                           this.GetName(complexType.BaseXmlSchemaType.QualifiedName, null) :
                           string.Empty,
                Type = ObjectTypes.ComplexType
            };

            // TODO: More complicated logic to determine if a restriction is being applied
            if (this.complexTypes.Count(y => y.Name == newSimpleObject.Name) > 0)
            {
                return(this.complexTypes.SingleOrDefault(y => y.Name == newSimpleObject.Name));
            }

            if (IsRecurring(newSimpleObject))
            {
                return(null);
            }

            if (!this.initializing || newSimpleObject.Depth <= maxInitialDepth)
            {
                newSimpleObject.InitializeChildren(newSimpleObject, complexType);
            }

            this.complexTypes.Add(newSimpleObject);

            return(newSimpleObject);
        }