Example #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);
        }
Example #2
0
        // TODO: Should we add a global XObject dictionary keyed by object so that we can cross-refernce back to non-ASTNode literals?
        private bool ParseChildXObjectToElement(AstNode parentASTNode, XObject xObject, XName xName, string xValue, PropertyInfo propertyToBind, XmlIRDocumentType docType)
        {
            bool mapped = false;

            object convertedLiteralValue;

            if (IfLiteralTypeTryConvert(propertyToBind.PropertyType, xValue, out convertedLiteralValue))  // GOTO: Literal Type Handling Code
            {
                BindProperty(propertyToBind, parentASTNode, convertedLiteralValue, xObject, false);
                return(true);
            }
            else if (IsXObjectValueTextOnly(xObject))  // GOTO: ASTNode Reference (Lookup) Handling Code
            {
                BindingItem bindingItem = new BindingItem(propertyToBind, xObject, xValue, parentASTNode, _ScopeManager.Clone());
                if (!BindASTNodeReference(bindingItem))
                {
                    this._LateBindingItems.Add(bindingItem);
                }
                return(true);
            }
            else // GOTO: ASTNode Child Element (recursive descent) Handling Code  // xObject maps to a list of known IASTNode types
            {
                // TODO: Do we need to check this cast or is it guaranteed safe?
                AstNode astNode = CreateASTNodeInstance((XElement)xObject, parentASTNode);
                if (astNode != null) // xObject maps directly to a known IASTNode type
                {
                    BindProperty(propertyToBind, parentASTNode, astNode, xObject, false);
                    // TODO: Do we need to check this cast or is it guaranteed safe?
                    parseElement((XElement)xObject, astNode, docType);
                    return(true);
                }
            }
            return(mapped);
        }
Example #3
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;
        }
Example #4
0
        // TODO: Should we add a global XObject dictionary keyed by object so that we can cross-refernce back to non-ASTNode literals?
        private bool ParseChildXObjectToElement(AstNode parentASTNode, XObject xObject, XName xName, string xValue, PropertyInfo propertyToBind, XmlIRDocumentType docType)
        {
            bool mapped = false;

            object convertedLiteralValue;
            if (IfLiteralTypeTryConvert(propertyToBind.PropertyType, xValue, out convertedLiteralValue))  // GOTO: Literal Type Handling Code
            {
                BindProperty(propertyToBind, parentASTNode, convertedLiteralValue, xObject, false);
                return true;
            }
            else if (IsXObjectValueTextOnly(xObject))  // GOTO: ASTNode Reference (Lookup) Handling Code
            {
                BindingItem bindingItem = new BindingItem(propertyToBind, xObject, xValue, parentASTNode, _ScopeManager.Clone());
                if (!BindASTNodeReference(bindingItem))
                {
                    this._LateBindingItems.Add(bindingItem);
                }
                return true;
            }
            else // GOTO: ASTNode Child Element (recursive descent) Handling Code  // xObject maps to a list of known IASTNode types
            {
                // TODO: Do we need to check this cast or is it guaranteed safe?
                AstNode astNode = CreateASTNodeInstance((XElement)xObject, parentASTNode);
                if (astNode != null) // xObject maps directly to a known IASTNode type
                {
                    BindProperty(propertyToBind, parentASTNode, astNode, xObject, false);
                    // TODO: Do we need to check this cast or is it guaranteed safe?
                    parseElement((XElement)xObject, astNode, docType);
                    return true;
                }
            }
            return mapped;
        }