Exemplo n.º 1
0
        /// <summary>
        /// Creates a group that contains all of the types that inherit from a given type,
        /// as well as the type itself. Reference this group when any inherited type is suitable.
        /// </summary>
        private void AddTypeDescendents(EffectiveType entityType, XmlSchema xsd)
        {
            // Example of inheritance declaration
            //<xs:group name="is_person">
            //  <xs:choice>
            //    <xs:element ref="person" />
            //    <xs:element ref="employee" />
            //    <xs:element ref="manager" />
            //  </xs:choice>
            //</xs:group>

            // Create a group, named "is_%typename%"
            var isType = new XmlSchemaGroup();

            isType.Name     = NameDeclared("is_" + entityType.Alias.Value, entityType.Alias.Namespace);
            isType.Particle = new XmlSchemaChoice();

            // Determine valid descendents
            IEnumerable <Entity> descendents;
            bool isSealed = _schemaManager.GetBoolFieldValue(entityType.Type, Aliases2.IsSealed);

            if (isSealed)
            {
                descendents = new List <Entity> {
                    entityType.Type
                }
            }
            ;
            else
            {
                descendents = _schemaManager.GetDecendants(entityType.Type);
            }

            // Render each type
            foreach (EffectiveType desc in EffectiveTypes(descendents))
            {
                bool isAbstract = _schemaManager.GetBoolFieldValue(desc.Type, Aliases2.IsAbstract);
                if (isAbstract)
                {
                    continue;
                }

                var derivedType = new XmlSchemaElement();
                derivedType.RefName = NameUsed(desc.Alias.ToQualifiedName());
                isType.Particle.Items.Add(derivedType);
            }
            xsd.Items.Add(isType);
        }