示例#1
0
        private bool BindASTNodeReference(BindingItem item)
        {
            Type t = item.BoundProperty.PropertyType;

            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)
            {
                BindProperty(item.BoundProperty, item.ParentASTNode, boundASTNode, item.XObject, true);
                return(true);
            }
            return(false);
        }
示例#2
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);
        }