Example #1
0
        // Token: 0x06006E14 RID: 28180 RVA: 0x001FAFB8 File Offset: 0x001F91B8
        private void PushPropertyToStack(string propertyName, ILocalizabilityInheritable node)
        {
            Stack <ILocalizabilityInheritable> stack;

            if (this._propertyInheritanceTreeStack.ContainsKey(propertyName))
            {
                stack = this._propertyInheritanceTreeStack[propertyName];
            }
            else
            {
                stack = new Stack <ILocalizabilityInheritable>();
                this._propertyInheritanceTreeStack.Add(propertyName, stack);
            }
            stack.Push(node);
        }
Example #2
0
        private void PushPropertyToStack(string propertyName, ILocalizabilityInheritable node)
        {
            Stack <ILocalizabilityInheritable> stackForProperty;

            if (_propertyInheritanceTreeStack.ContainsKey(propertyName))
            {
                // get the stack
                stackForProperty = _propertyInheritanceTreeStack[propertyName];
            }
            else
            {
                stackForProperty = new Stack <ILocalizabilityInheritable>();
                _propertyInheritanceTreeStack.Add(propertyName, stackForProperty);
            }

            // push the node
            stackForProperty.Push(node);
        }
        /// <summary>
        /// Combine inheritable attributes, and propegate it down the tree.        
        /// </summary>
        /// <param name="node">current node</param>
        /// <param name="localizabilityFromSource">localizability defined in source code</param>
        /// <returns>
        /// The LocalizabilityAttribute to used for this node. It is not the same as the 
        /// inheritable attributes of the node when the node is set to Ignore.    
        /// </returns>
        /// <remarks>We always walk the baml tree in depth-first order</remarks>
        private LocalizabilityAttribute CombineAndPropagateInheritanceValues(
            ILocalizabilityInheritable  node, 
            LocalizabilityAttribute     localizabilityFromSource
            )
        {
            if (node == null )
            {
                return localizabilityFromSource;
            }

            // If this node's inheritable localizability has been constructed, we can skip it
            // This can happen when recursively format the content
            if (node.InheritableAttribute != null)
            {
                return (!node.IsIgnored) ? node.InheritableAttribute : LocalizabilityIgnore;
            }
        
            // To test wether the current node needs to inherit values from parents. 
            // It inherits values if: 
            // o This node is set to Ignore, in which case it propagates parent values. 
            // o Some of its attributes set to Inherit.
            if ( localizabilityFromSource.Category      != LocalizationCategory.Ignore
              && localizabilityFromSource.Category      != LocalizationCategory.Inherit 
              && localizabilityFromSource.Readability   != Readability.Inherit
              && localizabilityFromSource.Modifiability != Modifiability.Inherit)
            {
                // just return the same one because no value is inherited
                node.InheritableAttribute = localizabilityFromSource;
                return node.InheritableAttribute;
            }          

            // find the ancestor to inherit values now.
            ILocalizabilityInheritable ancestor = node.LocalizabilityAncestor;            

            // find out the attribute that is inheritable from above
            LocalizabilityAttribute inheritableAttribute = ancestor.InheritableAttribute; 

            if (inheritableAttribute == null)
            {
                // if ancestor's inheritable value isn't resolved yet, we recursively 
                // resolve it here.
                BamlStartElementNode elementNode = ancestor as BamlStartElementNode;
                if (elementNode != null)
                {
                    string formattingTag;
                    GetLocalizabilityForElementNode(elementNode, out inheritableAttribute, out formattingTag);
                }
                else 
                {
                    BamlStartComplexPropertyNode propertyNode = ancestor as BamlStartComplexPropertyNode;
                    GetLocalizabilityForPropertyNode(propertyNode, out inheritableAttribute);
                }

                CombineAndPropagateInheritanceValues(ancestor, inheritableAttribute);
                
                inheritableAttribute = ancestor.InheritableAttribute;
                Debug.Assert(inheritableAttribute != null);
            }
                             
            // if this item is set to ignore
            if ( localizabilityFromSource.Category == LocalizationCategory.Ignore)
            {
                // It propagates ancestor's inheritable localizability, but it will use
                // its own value declared in source.
                // We also mark this node as being "Ignored" in the inheritance tree to signal that
                // this node is not using the inheritance value.
                node.InheritableAttribute = inheritableAttribute;
                node.IsIgnored = true; 
                return LocalizabilityIgnore;
            }
            
            // the item is not set to ignore, so we process the inheritable values
            BamlTreeNode treeNode = (BamlTreeNode) node;
            switch (treeNode.NodeType)
            {
                case BamlNodeType.StartElement :
                case BamlNodeType.LiteralContent :
                {
                    // if everything set to inherit, we just return the inheritable localizability
                    if (localizabilityFromSource.Category == LocalizationCategory.Inherit
                      && localizabilityFromSource.Readability == Readability.Inherit
                      && localizabilityFromSource.Modifiability == Modifiability.Inherit)
                    {
                        // just propagate the ancestor's localizability.
                        node.InheritableAttribute = inheritableAttribute;
                    }
                    else
                    {
                        // set new inherited values
                        node.InheritableAttribute = CreateInheritedLocalizability(
                            localizabilityFromSource,
                            inheritableAttribute
                            );
                    }
                    break;
                }                
                case BamlNodeType.Property :
                case BamlNodeType.StartComplexProperty :
                {
                    ILocalizabilityInheritable parent = (ILocalizabilityInheritable) treeNode.Parent;
                
                    // Find the mininum localizability of the containing class and 
                    // parent property. Parent property means the proeprty from parent node that 
                    // has the same name.
                    LocalizabilityAttribute inheritedAttribute = CombineMinimumLocalizability(
                        inheritableAttribute,
                        parent.InheritableAttribute
                        );

                    node.InheritableAttribute = CreateInheritedLocalizability(
                        localizabilityFromSource,
                        inheritedAttribute
                        );

                    if (parent.IsIgnored && localizabilityFromSource.Category == LocalizationCategory.Inherit)
                    {
                        // If the parent node is Ignore and this property is set to inherit, then 
                        // this property node is to be ignore as well. We set the the "Ignore" flag so that
                        // the node will always be ignored without looking at the source localizability again. 
                        node.IsIgnored = true;
                        return LocalizabilityIgnore;
                    }                        
                    break;
                }
                default: 
                {
                    Debug.Assert(false, "Can't process localizability attribute on nodes other than Element, Property and LiteralContent.");
                    break;
                }
            }            

            return node.InheritableAttribute;            
        }
        /// <summary>
        /// Combine inheritable attributes, and propegate it down the tree.
        /// </summary>
        /// <param name="node">current node</param>
        /// <param name="localizabilityFromSource">localizability defined in source code</param>
        /// <returns>
        /// The LocalizabilityAttribute to used for this node. It is not the same as the
        /// inheritable attributes of the node when the node is set to Ignore.
        /// </returns>
        /// <remarks>We always walk the baml tree in depth-first order</remarks>
        private LocalizabilityAttribute CombineAndPropagateInheritanceValues(
            ILocalizabilityInheritable node,
            LocalizabilityAttribute localizabilityFromSource
            )
        {
            if (node == null)
            {
                return(localizabilityFromSource);
            }

            // If this node's inheritable localizability has been constructed, we can skip it
            // This can happen when recursively format the content
            if (node.InheritableAttribute != null)
            {
                return((!node.IsIgnored) ? node.InheritableAttribute : LocalizabilityIgnore);
            }

            // To test wether the current node needs to inherit values from parents.
            // It inherits values if:
            // o This node is set to Ignore, in which case it propagates parent values.
            // o Some of its attributes set to Inherit.
            if (localizabilityFromSource.Category != LocalizationCategory.Ignore &&
                localizabilityFromSource.Category != LocalizationCategory.Inherit &&
                localizabilityFromSource.Readability != Readability.Inherit &&
                localizabilityFromSource.Modifiability != Modifiability.Inherit)
            {
                // just return the same one because no value is inherited
                node.InheritableAttribute = localizabilityFromSource;
                return(node.InheritableAttribute);
            }

            // find the ancestor to inherit values now.
            ILocalizabilityInheritable ancestor = node.LocalizabilityAncestor;

            // find out the attribute that is inheritable from above
            LocalizabilityAttribute inheritableAttribute = ancestor.InheritableAttribute;

            if (inheritableAttribute == null)
            {
                // if ancestor's inheritable value isn't resolved yet, we recursively
                // resolve it here.
                BamlStartElementNode elementNode = ancestor as BamlStartElementNode;
                if (elementNode != null)
                {
                    string formattingTag;
                    GetLocalizabilityForElementNode(elementNode, out inheritableAttribute, out formattingTag);
                }
                else
                {
                    BamlStartComplexPropertyNode propertyNode = ancestor as BamlStartComplexPropertyNode;
                    GetLocalizabilityForPropertyNode(propertyNode, out inheritableAttribute);
                }

                CombineAndPropagateInheritanceValues(ancestor, inheritableAttribute);

                inheritableAttribute = ancestor.InheritableAttribute;
                Debug.Assert(inheritableAttribute != null);
            }

            // if this item is set to ignore
            if (localizabilityFromSource.Category == LocalizationCategory.Ignore)
            {
                // It propagates ancestor's inheritable localizability, but it will use
                // its own value declared in source.
                // We also mark this node as being "Ignored" in the inheritance tree to signal that
                // this node is not using the inheritance value.
                node.InheritableAttribute = inheritableAttribute;
                node.IsIgnored            = true;
                return(LocalizabilityIgnore);
            }

            // the item is not set to ignore, so we process the inheritable values
            BamlTreeNode treeNode = (BamlTreeNode)node;

            switch (treeNode.NodeType)
            {
            case BamlNodeType.StartElement:
            case BamlNodeType.LiteralContent:
            {
                // if everything set to inherit, we just return the inheritable localizability
                if (localizabilityFromSource.Category == LocalizationCategory.Inherit &&
                    localizabilityFromSource.Readability == Readability.Inherit &&
                    localizabilityFromSource.Modifiability == Modifiability.Inherit)
                {
                    // just propagate the ancestor's localizability.
                    node.InheritableAttribute = inheritableAttribute;
                }
                else
                {
                    // set new inherited values
                    node.InheritableAttribute = CreateInheritedLocalizability(
                        localizabilityFromSource,
                        inheritableAttribute
                        );
                }
                break;
            }

            case BamlNodeType.Property:
            case BamlNodeType.StartComplexProperty:
            {
                ILocalizabilityInheritable parent = (ILocalizabilityInheritable)treeNode.Parent;

                // Find the mininum localizability of the containing class and
                // parent property. Parent property means the proeprty from parent node that
                // has the same name.
                LocalizabilityAttribute inheritedAttribute = CombineMinimumLocalizability(
                    inheritableAttribute,
                    parent.InheritableAttribute
                    );

                node.InheritableAttribute = CreateInheritedLocalizability(
                    localizabilityFromSource,
                    inheritedAttribute
                    );

                if (parent.IsIgnored && localizabilityFromSource.Category == LocalizationCategory.Inherit)
                {
                    // If the parent node is Ignore and this property is set to inherit, then
                    // this property node is to be ignore as well. We set the the "Ignore" flag so that
                    // the node will always be ignored without looking at the source localizability again.
                    node.IsIgnored = true;
                    return(LocalizabilityIgnore);
                }
                break;
            }

            default:
            {
                Debug.Assert(false, "Can't process localizability attribute on nodes other than Element, Property and LiteralContent.");
                break;
            }
            }

            return(node.InheritableAttribute);
        }
 private void PushPropertyToStack(string propertyName, ILocalizabilityInheritable node)
 {
     Stack<ILocalizabilityInheritable> stackForProperty;
     if (_propertyInheritanceTreeStack.ContainsKey(propertyName))
     {
         // get the stack
         stackForProperty = _propertyInheritanceTreeStack[propertyName];             
     }
     else
     {
         stackForProperty = new Stack<ILocalizabilityInheritable>();
         _propertyInheritanceTreeStack.Add(propertyName, stackForProperty);
     }
     
     // push the node
     stackForProperty.Push(node);                            
 }
        // Token: 0x06006EBA RID: 28346 RVA: 0x001FD2AC File Offset: 0x001FB4AC
        private LocalizabilityAttribute CombineAndPropagateInheritanceValues(ILocalizabilityInheritable node, LocalizabilityAttribute localizabilityFromSource)
        {
            if (node == null)
            {
                return(localizabilityFromSource);
            }
            if (node.InheritableAttribute != null)
            {
                if (node.IsIgnored)
                {
                    return(this.LocalizabilityIgnore);
                }
                return(node.InheritableAttribute);
            }
            else
            {
                if (localizabilityFromSource.Category != LocalizationCategory.Ignore && localizabilityFromSource.Category != LocalizationCategory.Inherit && localizabilityFromSource.Readability != Readability.Inherit && localizabilityFromSource.Modifiability != Modifiability.Inherit)
                {
                    node.InheritableAttribute = localizabilityFromSource;
                    return(node.InheritableAttribute);
                }
                ILocalizabilityInheritable localizabilityAncestor = node.LocalizabilityAncestor;
                LocalizabilityAttribute    inheritableAttribute   = localizabilityAncestor.InheritableAttribute;
                if (inheritableAttribute == null)
                {
                    BamlStartElementNode bamlStartElementNode = localizabilityAncestor as BamlStartElementNode;
                    if (bamlStartElementNode != null)
                    {
                        string text;
                        this.GetLocalizabilityForElementNode(bamlStartElementNode, out inheritableAttribute, out text);
                    }
                    else
                    {
                        BamlStartComplexPropertyNode node2 = localizabilityAncestor as BamlStartComplexPropertyNode;
                        this.GetLocalizabilityForPropertyNode(node2, out inheritableAttribute);
                    }
                    this.CombineAndPropagateInheritanceValues(localizabilityAncestor, inheritableAttribute);
                    inheritableAttribute = localizabilityAncestor.InheritableAttribute;
                }
                if (localizabilityFromSource.Category == LocalizationCategory.Ignore)
                {
                    node.InheritableAttribute = inheritableAttribute;
                    node.IsIgnored            = true;
                    return(this.LocalizabilityIgnore);
                }
                BamlTreeNode bamlTreeNode = (BamlTreeNode)node;
                BamlNodeType nodeType     = bamlTreeNode.NodeType;
                if (nodeType <= BamlNodeType.Property)
                {
                    if (nodeType != BamlNodeType.StartElement)
                    {
                        if (nodeType != BamlNodeType.Property)
                        {
                            goto IL_174;
                        }
                        goto IL_127;
                    }
                }
                else
                {
                    if (nodeType == BamlNodeType.StartComplexProperty)
                    {
                        goto IL_127;
                    }
                    if (nodeType != BamlNodeType.LiteralContent)
                    {
                        goto IL_174;
                    }
                }
                if (localizabilityFromSource.Category == LocalizationCategory.Inherit && localizabilityFromSource.Readability == Readability.Inherit && localizabilityFromSource.Modifiability == Modifiability.Inherit)
                {
                    node.InheritableAttribute = inheritableAttribute;
                    goto IL_174;
                }
                node.InheritableAttribute = this.CreateInheritedLocalizability(localizabilityFromSource, inheritableAttribute);
                goto IL_174;
IL_127:
                ILocalizabilityInheritable localizabilityInheritable = (ILocalizabilityInheritable)bamlTreeNode.Parent;
                LocalizabilityAttribute inheritable = this.CombineMinimumLocalizability(inheritableAttribute, localizabilityInheritable.InheritableAttribute);
                node.InheritableAttribute = this.CreateInheritedLocalizability(localizabilityFromSource, inheritable);
                if (localizabilityInheritable.IsIgnored && localizabilityFromSource.Category == LocalizationCategory.Inherit)
                {
                    node.IsIgnored = true;
                    return(this.LocalizabilityIgnore);
                }
IL_174:
                return(node.InheritableAttribute);
            }
        }