Exemplo n.º 1
0
        /// <summary>
        /// Visitor implementation. Processes the passed element
        /// adding the member elements defined in the customization.
        /// </summary>
        /// <param name="element"></param>
        public override void Visit(VisitableElementComplexType element)
        {
            base.Visit(element);

            #region Add Members to Type declarations
            if (CurrentType != null)
            {
                ArrayList nodes = Retriever.RetrieveCustomization(
                    element, NodeType.Type);
                ParseNodes(nodes, element.Name);
            }
            #endregion

            #region Add Members to Collection declarations
            string name = element.Name + Configuration.CollectionNaming;
            foreach (CodeTypeDeclaration type in CurrentNamespace.Types)
            {
                if (type.Name == name)
                {
                    CurrentType = type;
                    break;
                }
            }

            if (CurrentType != null)
            {
                ArrayList nodes = Retriever.RetrieveCustomization(
                    element, NodeType.Collection);
                ParseNodes(nodes, element.Name);
            }
            #endregion
        }
Exemplo n.º 2
0
        /// <summary>
        /// Visitor implementation. Processes the passed element
        /// adding the corresponding constructors.
        /// </summary>
        /// <param name="element"></param>
        public override void Visit(VisitableElementComplexType element)
        {
            base.Visit(element);

            if (CurrentType != null)
            {
                AddConstructor(element, Retriever.RetrieveCustomization(
                                   element, NodeType.Type));
            }

            ArrayList nodes = Retriever.RetrieveCustomization(
                element, NodeType.Collection);
            string name = element.Name + Configuration.CollectionNaming;

            if (nodes.Count != 0)
            {
                CurrentType = null;
                foreach (CodeTypeDeclaration type in CurrentNamespace.Types)
                {
                    if (type.Name == name)
                    {
                        CurrentType = type;
                        break;
                    }
                }
                if (CurrentType != null)
                {
                    AddConstructor(element, nodes);
                }
                // TODO: Constructor isn't added!!!
            }
        }
Exemplo n.º 3
0
        public override void Visit(VisitableElementComplexType element)
        {
            base.Visit(element);

            if (CurrentType == null)
            {
                ArrayList nodes = Retriever.RetrieveCustomization(element, NodeType.Type);

                if (nodes.Count != 0 || Retriever.Files.Count == 0)
                {
                    CodeTypeDeclaration type = new CodeTypeDeclaration(element.TypeName);
                    type.CustomAttributes.AddRange(CodeDomHelper.BuildCustomAttributes(nodes));
                    type.BaseTypes.AddRange(CodeDomHelper.BuildBaseTypes(nodes));
                    // Append unhandled attributes to the type UserData property, for use by custom visitors.
                    XmlAttribute[] attributes = element.SchemaObject.UnhandledAttributes;
                    if (attributes != null)
                    {
                        foreach (XmlAttribute attr in attributes)
                        {
                            type.UserData.Add(attr.LocalName, attr);
                        }
                    }

                    CurrentNamespace.Types.Add(type);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// If no customization files are defined, add an empty read/write property.
        /// </summary>
        /// <remarks>
        /// Beware that with this configuration code may not compile because of the
        /// warnings about the properties not returning any value.
        /// </remarks>
        private void AddProperty(BaseLeafSchemaElement element, Type type)
        {
            ArrayList nodes = Retriever.RetrieveCustomization(element);

            if (nodes.Count != 0)
            {
                // Original type name is the current type name without the
                // type naming convention appended during tree parsing.
                string name = (Configuration.TypeNaming != String.Empty) ?
                              CurrentType.Name.Replace(Configuration.TypeNaming, "") :
                              CurrentType.Name;

                CodeMemberProperty prop = CodeDomHelper.BuildProperty(
                    name, element.Name, Configuration.TypeNaming,
                    Configuration.CollectionNaming,
                    type, nodes, CurrentNamespace);

                XmlAttribute[] attributes = ((XmlSchemaAnnotated)element.SchemaObject).UnhandledAttributes;
                if (attributes != null)
                {
                    foreach (XmlAttribute attr in attributes)
                    {
                        prop.UserData.Add(attr.LocalName, attr);
                    }
                }

                CurrentType.Members.Add(prop);
            }
            else if (Retriever.Files.Count == 0)
            {
                CodeMemberProperty prop = new CodeMemberProperty();
                prop.Attributes = MemberAttributes.Public;
                prop.Name       = element.Name;
                prop.Type       = new CodeTypeReference(type);
                prop.HasGet     = true;
                prop.HasSet     = true;
                CurrentType.Members.Add(prop);
            }
        }
Exemplo n.º 5
0
        public override void Visit(VisitableElementComplexType element)
        {
            ArrayList nodes = Retriever.RetrieveCustomization(element, NodeType.Collection);
            string    name  = element.Name + Configuration.CollectionNaming;

            if (nodes.Count != 0)
            {
                CodeTypeDeclaration type = null;

                foreach (CodeTypeDeclaration obj in CurrentNamespace.Types)
                {
                    if (obj.Name == name)
                    {
                        type = obj;
                        break;
                    }
                }

                if (type == null)
                {
                    type = new CodeTypeDeclaration(name);
                    CurrentNamespace.Types.Add(type);
                    // Mark the type as being a collection.
                    type.UserData.Add("IsCollection", true);

                    // Append unhandled attributes to the type UserData property, for use by custom visitors.
                    XmlAttribute[] attributes = element.SchemaObject.UnhandledAttributes;
                    if (attributes != null)
                    {
                        foreach (XmlAttribute attr in attributes)
                        {
                            type.UserData.Add(attr.LocalName, attr);
                        }
                    }
                }

                type.CustomAttributes.AddRange(CodeDomHelper.BuildCustomAttributes(nodes));
                type.BaseTypes.AddRange(CodeDomHelper.BuildBaseTypes(nodes));
            }

            // If the element is contained in another element, and generateContainerProperty configuration
            // is "true", add the corresponding property if it isn't already present.
            if (Configuration.InnerData.GenerateContainerProperty && element.Parent != null &&
                element.Parent is VisitableElementComplexType)
            {
                CodeTypeDeclaration enclosing = null;
                foreach (CodeTypeDeclaration type in CurrentNamespace.Types)
                {
                    if (type.Name == element.Parent.TypeName)
                    {
                        enclosing = type;
                        break;
                    }
                }

                // If we find the parent type and the property hasn't been defined already
                if (enclosing != null)
                {
                    bool existing = false;
                    foreach (CodeTypeMember prop in enclosing.Members)
                    {
                        if (prop.Name == element.Name)
                        {
                            existing = true;
                            break;
                        }
                    }

                    if (!existing)
                    {
                        CodeMemberProperty prop = new CodeMemberProperty();
                        prop.Name       = element.Name;
                        prop.Attributes = MemberAttributes.Public;
                        // TODO: Review if it is necessary to add an attribute to specify getter and setter for the property.
                        prop.HasGet = true;
                        prop.HasSet = true;

                        // Do we have a custom Collection?
                        if (nodes.Count != 0)
                        {
                            prop.Type = new CodeTypeReference(element.Name + Configuration.CollectionNaming);
                        }
                        else
                        {
                            prop.Type = new CodeTypeReference(element.TypeName, 1);
                        }

                        enclosing.Members.Add(prop);
                    }
                }
            }
        }