Exemple #1
0
        public static DynamicEntityPropertyDescription Create(XmlNode node)
        {
            DynamicEntityPropertyDescription property = new DynamicEntityPropertyDescription();

            if (node.Name != "Property")
            {
                DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.InvalidXmlDocument, "A start element expected");
                return(null);
            }

            property._name = node.Attributes["name"].InnerXml;

            if (node.FirstChild.Name != "Type")
            {
                DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.InvalidXmlDocument, string.Format("Node 'Type' expected but {0} found", node.FirstChild.Name));
                return(null);
            }
            property._typeName = node.FirstChild.InnerXml;
            if (property.TypeName.StartsWith("List"))
            {
                property._isList = true;
            }
            else
            {
                property._isList = false;
            }

            if (node.ChildNodes.Count > 1)
            {
                foreach (XmlNode n in node.ChildNodes)
                {
                    if (n.Name == "Type")
                    {
                        continue;
                    }
                    else if (n.Name == "Attributes")
                    {
                        foreach (XmlNode childNode in n.ChildNodes)
                        {
                            DynamicEntityAttributeDescription attr = DynamicEntityAttributeDescription.Create(childNode);
                            if (attr != null)
                            {
                                property._attributes.Add(attr.Name, attr);
                            }
                            else
                            {
                                DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.InvalidStructural, "The 'Attribute' object was not build correctly");
                                return(null);
                            }
                        }
                    }
                    else if (n.Name == "get")
                    {
                        property._getMethod = n.InnerXml;
                    }
                    else if (n.Name == "set")
                    {
                        property._setMethod = n.InnerXml;
                    }
                    else
                    {
                        DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.UnexpectedNode, string.Format("Node '{0}' is unexpected", n.Name));
                        return(null);
                    }
                }
            }

            return(property);
        }
Exemple #2
0
        public static DynamicEntityDescription Create(XmlReader reader)
        {
            XmlReaderSettings sett = new XmlReaderSettings();

            sett.IgnoreComments = true;
            sett.IgnoreProcessingInstructions = true;
            sett.IgnoreWhitespace             = true;

            XmlReader rdr = XmlReader.Create(reader, sett);

            XmlDocument doc = new XmlDocument();

            doc.Load(rdr);

            if (doc.ChildNodes.Count != 1)
            {
                DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.InvalidXmlDocument, "The xml document must only one node describing an entity");
                return(null);
            }
            XmlNode node = doc.ChildNodes[0];

            DynamicEntityDescription entity = new DynamicEntityDescription();

            entity._name = node.Name;

            foreach (XmlNode n in node.ChildNodes)
            {
                if (n.Name == "Usings")
                {
                    foreach (XmlNode nn in n.ChildNodes)
                    {
                        if (nn.Name == "Using")
                        {
                            entity._usings.Add(nn.InnerXml);
                        }
                        else
                        {
                            DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.UnexpectedNode, string.Format("Node 'Using' expected but '{0}' found", node.FirstChild.Name));
                            return(null);
                        }
                    }
                }
                else if (n.Name == "Namespace")
                {
                    entity._namespace = n.InnerXml;
                }
                else if (n.Name == "Attributes")
                {
                    foreach (XmlNode nn in n.ChildNodes)
                    {
                        DynamicEntityAttributeDescription attribute = DynamicEntityAttributeDescription.Create(nn);
                        if (nn != null)
                        {
                            entity._attributes.Add(attribute.Name, attribute);
                        }
                        else
                        {
                            DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.InvalidStructural, "The 'Attribute' object was not build correctly");
                            return(null);
                        }
                    }
                }
                else if (n.Name == "Properties")
                {
                    foreach (XmlNode nn in n.ChildNodes)
                    {
                        DynamicEntityPropertyDescription property = DynamicEntityPropertyDescription.Create(nn);
                        if (property != null)
                        {
                            entity._properties.Add(property.Name, property);
                        }
                        else
                        {
                            DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.InvalidStructural, "The 'Property' object was not build correctly");
                            return(null);
                        }
                    }
                }
                else
                {
                    DynamicEntityBuildingError err = new DynamicEntityBuildingError(ErrorType.UnexpectedNode, string.Format("Node 'Usings', 'Namespace', 'Attributes' or 'Properties' expected but '{0}' found", node.FirstChild.Name));
                    return(null);
                }
            }

            return(entity);
        }