Esempio n. 1
0
        private bool FindASTNodeReferenceForNewObject(XmlIR xmlIR, NewBindingItem item)
        {
            Type t = item.node.GetType();

            if (IsContainerOf(typeof(ICollection <object>), t))
            {
                t = t.GetGenericArguments()[0];
            }

            string  value        = item.XValue;
            AstNode boundASTNode = null;
            AstParserScopeManager scopeManager = item.ScopeManager.Clone();

            // Walk scopes
            while (boundASTNode == null && !scopeManager.IsEmpty)
            {
                boundASTNode = FindASTNode(t, scopeManager.GetScopedName(value));
                scopeManager.Pop();
            }

            // Attempt scopeless binding
            if (boundASTNode == null)
            {
                boundASTNode = FindASTNode(t, value);
            }

            if (boundASTNode != null)
            {
                XElement        xElement     = new XElement((XElement)boundASTNode.BoundXElement);
                XmlSchemaObject schemaObject = ((XElement)boundASTNode.BoundXElement).GetSchemaInfo().SchemaElement;
                xElement.SetAttributeValue("AsClassOnly", false);
                xElement.SetAttributeValue("Name", item.node.Name);
                Dictionary <string, string> dictParams = new Dictionary <string, string>();
                foreach (XElement param in xElement.Elements(XName.Get("Argument", GetDefaultXMLNamespace(boundASTNode))))
                {
                    string     sParam     = param.Attribute("Name").Value;
                    XAttribute xAttribute = (item.node.BoundXElement as XElement).
                                            Element(XName.Get("New", GetDefaultXMLNamespace(item.node))).Attribute(sParam);
                    if (xAttribute != null)
                    {
                        dictParams.Add("{argument(" + sParam + ")}", xAttribute.Value);
                    }
                    else
                    {
                        dictParams.Add("{argument(" + sParam + ")}", param.Attribute("DefaultValue").Value);
                    }
                }
                ReplaceParameters(xElement, dictParams);
                xmlIR.ValidateXElement(schemaObject, xElement);
                parseElement(xElement, item.node, item.docType);
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        private void ParseChildXObject(AstNode parentASTNode, XObject xObject, XName xName, string xValue, PropertyInfo propertyToBind, XmlIRDocumentType docType)
        {
            bool mapped = false;

            if (propertyToBind != null)
            {
                // TODO: Do we need to check this cast or is it guaranteed safe?
                if (IsContainerOf(typeof(ICollection <AstNode>), propertyToBind.PropertyType) && xObject is XElement && !IsFlattenedListOf(propertyToBind.PropertyType, (XElement)xObject))
                {
                    // REVIEW: We ignore the child attributes of the ICollection-bound xObject and we process its children with the same parentASTNode and a binding preset to the ICollection
                    mapped = true;
                    foreach (XElement xElement in ((XElement)xObject).Elements())
                    {
                        if (xElement.Name != XName.Get("Annotation", GetDefaultXMLNamespace(parentASTNode)))
                        {
                            mapped = mapped && ParseChildXObjectToElement(parentASTNode, xElement, xElement.Name, xElement.Value, propertyToBind, docType);
                        }
                    }
                }
                else
                {
                    mapped = ParseChildXObjectToElement(parentASTNode, xObject, xName, xValue, propertyToBind, docType);
                }
            }

            // Property could not be found or ASTNode instance could not be created
            if (!mapped)
            {
                if (!this._UnmappedProperties.ContainsKey(xName))
                {
                    this._UnmappedProperties.Add(xName, new List <AstNode>());
                }
                this._UnmappedProperties[xName].Add(parentASTNode);
                parentASTNode.UnmappedXObjects.Add(xObject);

                if (parentASTNode is AstNamedNode && xName == XName.Get("New", GetDefaultXMLNamespace(parentASTNode)))
                {
                    NewBindingItem bindingItem = new NewBindingItem(docType, xObject, ((XElement)xObject).Attribute("Class").Value, (AstNamedNode)parentASTNode, _ScopeManager.Clone());
                    this._NewObjectItems.Add(bindingItem);
                }
            }
        }
Esempio n. 3
0
        private bool FindASTNodeReferenceForNewObject(XmlIR xmlIR, NewBindingItem item)
        {
            Type t = item.node.GetType();
            if (IsContainerOf(typeof(ICollection<object>), t))
            {
                t = t.GetGenericArguments()[0];
            }

            string value = item.XValue;
            AstNode boundASTNode = null;
            AstParserScopeManager scopeManager = item.ScopeManager.Clone();

            // Walk scopes
            while (boundASTNode == null && !scopeManager.IsEmpty)
            {
                boundASTNode = FindASTNode(t, scopeManager.GetScopedName(value));
                scopeManager.Pop();
            }

            // Attempt scopeless binding
            if (boundASTNode == null)
            {
                boundASTNode = FindASTNode(t, value);
            }

            if (boundASTNode != null)
            {
                XElement xElement = new XElement((XElement)boundASTNode.BoundXElement);
                XmlSchemaObject schemaObject = ((XElement)boundASTNode.BoundXElement).GetSchemaInfo().SchemaElement;
                xElement.SetAttributeValue("AsClassOnly", false);
                xElement.SetAttributeValue("Name", item.node.Name);
                Dictionary<string, string> dictParams = new Dictionary<string, string>();
                foreach (XElement param in xElement.Elements(XName.Get("Argument", GetDefaultXMLNamespace(boundASTNode))))
                {
                    string sParam = param.Attribute("Name").Value;
                    XAttribute xAttribute = (item.node.BoundXElement as XElement).
                        Element(XName.Get("New", GetDefaultXMLNamespace(item.node))).Attribute(sParam);
                    if (xAttribute != null)
                    {
                        dictParams.Add("{argument(" + sParam + ")}", xAttribute.Value);
                    }
                    else
                    {
                        dictParams.Add("{argument(" + sParam + ")}", param.Attribute("DefaultValue").Value);
                    }
                }
                ReplaceParameters(xElement, dictParams);
                xmlIR.ValidateXElement(schemaObject, xElement);
                parseElement(xElement, item.node, item.docType);
                return true;
            }
            return false;
        }
Esempio n. 4
0
        private void ParseChildXObject(AstNode parentASTNode, XObject xObject, XName xName, string xValue, PropertyInfo propertyToBind, XmlIRDocumentType docType)
        {
            bool mapped = false;

            if (propertyToBind != null)
            {
                // TODO: Do we need to check this cast or is it guaranteed safe?
                if (IsContainerOf(typeof(ICollection<AstNode>), propertyToBind.PropertyType) && xObject is XElement && !IsFlattenedListOf(propertyToBind.PropertyType, (XElement)xObject))
                {
                    // REVIEW: We ignore the child attributes of the ICollection-bound xObject and we process its children with the same parentASTNode and a binding preset to the ICollection
                    mapped = true;
                    foreach (XElement xElement in ((XElement)xObject).Elements())
                    {
                        if (xElement.Name != XName.Get("Annotation", GetDefaultXMLNamespace(parentASTNode)))
                        {
                            mapped = mapped && ParseChildXObjectToElement(parentASTNode, xElement, xElement.Name, xElement.Value, propertyToBind, docType);
                        }
                    }
                }
                else
                {
                    mapped = ParseChildXObjectToElement(parentASTNode, xObject, xName, xValue, propertyToBind,docType);
                }
            }

            // Property could not be found or ASTNode instance could not be created
            if (!mapped)
            {
                if (!this._UnmappedProperties.ContainsKey(xName))
                {
                    this._UnmappedProperties.Add(xName, new List<AstNode>());
                }
                this._UnmappedProperties[xName].Add(parentASTNode);
                parentASTNode.UnmappedXObjects.Add(xObject);

                if (parentASTNode is AstNamedNode && xName == XName.Get("New", GetDefaultXMLNamespace(parentASTNode)))
                {
                    NewBindingItem bindingItem = new NewBindingItem(docType, xObject, ((XElement)xObject).Attribute("Class").Value, (AstNamedNode)parentASTNode, _ScopeManager.Clone());
                    this._NewObjectItems.Add(bindingItem);
                }
            }
        }