Beispiel #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);
        }
Beispiel #2
0
        private void parseElement(XElement element, AstNode astNode, XmlIRDocumentType docType)
        {
            this._ScopeManager.Push(astNode);
            ParseAttributes(element, astNode, docType);
            ParseChildElements(element, astNode, docType);
            this._ScopeManager.Pop();

            AstNamedNode astNamedNode = astNode as AstNamedNode;

            if (astNode is IPackageRootNode)
            {
                switch (docType)
                {
                case XmlIRDocumentType.SOURCE:
                    ((IPackageRootNode)astNode).Emit = true;
                    break;

                case XmlIRDocumentType.INCLUDE:
                    ((IPackageRootNode)astNode).Emit = false;
                    break;

                default:
                    throw new NotImplementedException(String.Format(Properties.Resources.ErrorUnknownDocType, docType.ToString()));
                }
            }
            if (astNamedNode != null && astNamedNode.Name != null)
            {
                // Guaranteed to work since all sub-dictionaries were initialized in PreLoadPropertyMappingsAndGlobalDictionary()
                this._GlobalASTNamedNodeDictionary[astNamedNode.GetType()][_ScopeManager.GetScopedName(astNamedNode.Name)] = astNamedNode;
            }
        }
Beispiel #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);
        }