Exemple #1
0
        /// <summary>
        /// Get the localizability of a CLR property
        /// </summary>
        private static void GetLocalizabilityForClrProperty(
            string propertyName,
            Type owner,
            out LocalizabilityAttribute localizability,
            out Type propertyType
            )
        {
            localizability = null;
            propertyType   = null;

            PropertyInfo info = owner.GetProperty(propertyName);

            if (info == null)
            {
                return; // couldn't find the Clr property
            }

            // we found the CLR property, set the type of the property
            propertyType = info.PropertyType;

            object[] locAttributes = info.GetCustomAttributes(
                TypeOfLocalizabilityAttribute, // type of the attribute
                true                           // search in base class
                );

            if (locAttributes.Length == 0)
            {
                return;
            }
            Debug.Assert(locAttributes.Length == 1, "Should have only 1 localizability attribute");

            // we found the attribute defined on the property
            localizability = (LocalizabilityAttribute)locAttributes[0];
        }
        // Token: 0x06006ECA RID: 28362 RVA: 0x001FDA24 File Offset: 0x001FBC24
        internal LocalizabilityAttribute Override(LocalizabilityAttribute attribute)
        {
            Modifiability        modifiability = attribute.Modifiability;
            Readability          readability   = attribute.Readability;
            LocalizationCategory category      = attribute.Category;
            bool flag = false;

            if (this.Modifiability != (Modifiability)(-1))
            {
                modifiability = this.Modifiability;
                flag          = true;
            }
            if (this.Readability != (Readability)(-1))
            {
                readability = this.Readability;
                flag        = true;
            }
            if (this.Category != (LocalizationCategory)(-1))
            {
                category = this.Category;
                flag     = true;
            }
            if (flag)
            {
                attribute = new LocalizabilityAttribute(category);
                attribute.Modifiability = modifiability;
                attribute.Readability   = readability;
            }
            return(attribute);
        }
 // Token: 0x06006EBC RID: 28348 RVA: 0x001FD4A0 File Offset: 0x001FB6A0
 private LocalizabilityAttribute CombineMinimumLocalizability(LocalizabilityAttribute first, LocalizabilityAttribute second)
 {
     if (first != null && second != null)
     {
         Readability          readability   = (Readability)Math.Min((int)first.Readability, (int)second.Readability);
         Modifiability        modifiability = (Modifiability)Math.Min((int)first.Modifiability, (int)second.Modifiability);
         LocalizationCategory category;
         if (first.Category == LocalizationCategory.NeverLocalize || second.Category == LocalizationCategory.NeverLocalize)
         {
             category = LocalizationCategory.NeverLocalize;
         }
         else if (first.Category == LocalizationCategory.Ignore || second.Category == LocalizationCategory.Ignore)
         {
             category = LocalizationCategory.Ignore;
         }
         else
         {
             category = ((first.Category != LocalizationCategory.None) ? first.Category : second.Category);
         }
         return(new LocalizabilityAttribute(category)
         {
             Readability = readability,
             Modifiability = modifiability
         });
     }
     if (first != null)
     {
         return(first);
     }
     return(second);
 }
        private void GetLocalizabilityForElementNode(
            BamlStartElementNode node,
            out LocalizabilityAttribute localizability,
            out string formattingTag
            )
        {
            localizability = null;
            formattingTag  = null;

            // get the names we need
            string assemblyName = node.AssemblyName;
            string className    = node.TypeFullName;

            // query the resolver
            ElementLocalizability result = _resolver.GetElementLocalizability(
                assemblyName,
                className
                );

            LocalizabilityGroup comment = null;

            comment = _resolver.GetLocalizabilityComment(node, BamlConst.ContentSuffix);

            if (comment != null)
            {
                localizability = comment.Override(result.Attribute);
            }
            else
            {
                localizability = result.Attribute;
            }

            formattingTag = result.FormattingTag;
        }
Exemple #5
0
        static DefaultAttributes()
        {
            // predefined localizability attributes
            DefinedAttributes = new Dictionary <object, LocalizabilityAttribute>(32);

            // nonlocalizable attribute
            LocalizabilityAttribute notReadable = new LocalizabilityAttribute(LocalizationCategory.None);

            notReadable.Readability = Readability.Unreadable;

            LocalizabilityAttribute notModifiable = new LocalizabilityAttribute(LocalizationCategory.None);

            notModifiable.Modifiability = Modifiability.Unmodifiable;

            // not localizable CLR types
            DefinedAttributes.Add(typeof(Boolean), notReadable);
            DefinedAttributes.Add(typeof(Byte), notReadable);
            DefinedAttributes.Add(typeof(SByte), notReadable);
            DefinedAttributes.Add(typeof(Char), notReadable);
            DefinedAttributes.Add(typeof(Decimal), notReadable);
            DefinedAttributes.Add(typeof(Double), notReadable);
            DefinedAttributes.Add(typeof(Single), notReadable);
            DefinedAttributes.Add(typeof(Int32), notReadable);
            DefinedAttributes.Add(typeof(UInt32), notReadable);
            DefinedAttributes.Add(typeof(Int64), notReadable);
            DefinedAttributes.Add(typeof(UInt64), notReadable);
            DefinedAttributes.Add(typeof(Int16), notReadable);
            DefinedAttributes.Add(typeof(UInt16), notReadable);
            DefinedAttributes.Add(typeof(Uri), notModifiable);
        }
        /// <summary>
        /// Create the inherited localizability attribute
        /// </summary>
        /// <param name="source">localizability attribute defined in source</param>
        /// <param name="inheritable">localizability attribute inheritable from above</param>
        /// <returns>LocalizabilityAttribute</returns>
        private LocalizabilityAttribute CreateInheritedLocalizability(
            LocalizabilityAttribute source,
            LocalizabilityAttribute inheritable
            )
        {
            LocalizationCategory category =
                (source.Category == LocalizationCategory.Inherit) ?
                inheritable.Category :
                source.Category;

            Readability readability =
                (source.Readability == Readability.Inherit) ?
                inheritable.Readability :
                source.Readability;

            Modifiability modifiability =
                (source.Modifiability == Modifiability.Inherit) ?
                inheritable.Modifiability :
                source.Modifiability;

            LocalizabilityAttribute attribute = new LocalizabilityAttribute(category);

            attribute.Readability   = readability;
            attribute.Modifiability = modifiability;
            return(attribute);
        }
Exemple #7
0
        /// <summary>
        /// Get the localizability attribute for a type
        /// </summary>
        internal static LocalizabilityAttribute GetDefaultAttribute(object type)
        {
            if (DefinedAttributes.ContainsKey(type))
            {
                LocalizabilityAttribute predefinedAttribute = DefinedAttributes[type];

                // create a copy of the predefined attribute and return the copy
                LocalizabilityAttribute result = new LocalizabilityAttribute(predefinedAttribute.Category);
                result.Readability   = predefinedAttribute.Readability;
                result.Modifiability = predefinedAttribute.Modifiability;
                return(result);
            }
            else
            {
                Type targetType = type as Type;
                if (targetType != null && targetType.IsValueType)
                {
                    // It is looking for the default value of a value type (i.e. struct and enum)
                    // we use this default.
                    LocalizabilityAttribute attribute = new LocalizabilityAttribute(LocalizationCategory.Inherit);
                    attribute.Modifiability = Modifiability.Unmodifiable;
                    return(attribute);
                }
                else
                {
                    return(DefaultAttribute);
                }
            }
        }
Exemple #8
0
        // Helper to override a localizability attribute. Not needed for compiler
        internal LocalizabilityAttribute Override(LocalizabilityAttribute attribute)
        {
            Modifiability        modifiability = attribute.Modifiability;
            Readability          readability   = attribute.Readability;
            LocalizationCategory category      = attribute.Category;

            bool overridden = false;

            if (((int)Modifiability) != InvalidValue)
            {
                modifiability = Modifiability;
                overridden    = true;
            }

            if (((int)Readability) != InvalidValue)
            {
                readability = Readability;
                overridden  = true;
            }

            if (((int)Category) != InvalidValue)
            {
                category   = Category;
                overridden = true;
            }

            if (overridden)
            {
                attribute = new LocalizabilityAttribute(category);
                attribute.Modifiability = modifiability;
                attribute.Readability   = readability;
            }

            return(attribute);
        }
Exemple #9
0
        public override LocalizabilityAttribute GetPropertyLocalizability(string assembly, string className, string property)
        {
            if (_externalResolver == null ||
                assembly == null || assembly.Length == 0 ||
                className == null || className.Length == 0 ||
                property == null || property.Length == 0)
            {
                return(DefaultAttribute);
            }

            string fullName = className + ":" + property;

            if (_propertyAttributeTable.ContainsKey(fullName))
            {
                // return cached value
                return(_propertyAttributeTable[fullName]);
            }
            else
            {
                LocalizabilityAttribute loc = _externalResolver.GetPropertyLocalizability(assembly, className, property);
                if (loc == null)
                {
                    loc = DefaultAttribute;
                }

                _propertyAttributeTable[fullName] = loc;
                return(loc);
            }
        }
        /// <summary>
        /// It combines the min values of two localizability attributes.
        /// </summary>
        /// <param name="first">first </param>
        /// <param name="second">second</param>
        /// <returns>LocalizabilityAttribute</returns>
        private LocalizabilityAttribute CombineMinimumLocalizability(
            LocalizabilityAttribute first,
            LocalizabilityAttribute second
            )
        {
            if (first == null || second == null)
            {
                return((first == null) ? second : first);
            }

            // min of two readability enum. The less the more restrictive.
            Readability readability = (Readability)Math.Min(
                (int)first.Readability,
                (int)second.Readability
                );

            // min of two Modifiability enum. The less the more restrictive.
            Modifiability modifiability = (Modifiability)Math.Min(
                (int)first.Modifiability,
                (int)second.Modifiability
                );

            // for category, NeverLocalize < Ignore < { all others } < None
            // If both categories belong to { all others }, first.Category wins
            LocalizationCategory category = LocalizationCategory.None;

            if (first.Category == LocalizationCategory.NeverLocalize ||
                second.Category == LocalizationCategory.NeverLocalize)
            {
                category = LocalizationCategory.NeverLocalize;
            }
            else if (first.Category == LocalizationCategory.Ignore ||
                     second.Category == LocalizationCategory.Ignore)
            {
                category = LocalizationCategory.Ignore;
            }
            else
            {
                category = (first.Category != LocalizationCategory.None) ?
                           first.Category :
                           second.Category;
            }

            LocalizabilityAttribute result = new LocalizabilityAttribute(category);

            result.Readability   = readability;
            result.Modifiability = modifiability;

            return(result);
        }
        /// <summary>
        /// return localizability of a property to the BamlLocalizer
        /// </summary>
        public override LocalizabilityAttribute GetPropertyLocalizability(
            string assembly,
            string className,
            string property
            )
        {
            LocalizabilityAttribute attribute = null;

            Type type = GetType(assembly, className);

            if (type != null)
            {
                // type of the property. The type can be retrieved from CLR property, or Attached property.
                Type clrPropertyType = null, attachedPropertyType = null;

                // we found the type. try to get to the property as Clr property
                GetLocalizabilityForClrProperty(
                    property,
                    type,
                    out attribute,
                    out clrPropertyType
                    );

                if (attribute == null)
                {
                    // we didn't find localizability as a Clr property on the type,
                    // try to get the property as attached property
                    GetLocalizabilityForAttachedProperty(
                        property,
                        type,
                        out attribute,
                        out attachedPropertyType
                        );
                }

                if (attribute == null)
                {
                    // if attached property doesn't have [LocalizabilityAttribute] defined,
                    // we get it from the type of the property.
                    attribute = (clrPropertyType != null) ?
                                GetLocalizabilityFromType(clrPropertyType)
                        : GetLocalizabilityFromType(attachedPropertyType);
                }
            }

            return(attribute);
        }
        /// <summary>
        /// Get localizability for attached property
        /// </summary>
        /// <param name="propertyName">property name</param>
        /// <param name="owner">owner type</param>
        /// <param name="localizability">out: localizability attribute</param>
        /// <param name="propertyType">out: type of the property</param>
        private void GetLocalizabilityForAttachedProperty(
            string propertyName,
            Type owner,
            out LocalizabilityAttribute localizability,
            out Type propertyType
            )
        {
            localizability = null;
            propertyType   = null;

            // if it is an attached property, it should have a dependency property with the name
            // <attached proeprty's name> + "Property"
            DependencyProperty attachedDp = DependencyPropertyFromName(
                propertyName, // property name
                owner
                );            // owner type

            if (attachedDp == null)
            {
                return;  // couldn't find the dp.
            }
            // we found the Dp, set the type of the property
            propertyType = attachedDp.PropertyType;

            FieldInfo fieldInfo = attachedDp.OwnerType.GetField(
                attachedDp.Name + "Property",
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Static | BindingFlags.FlattenHierarchy);

            Debug.Assert(fieldInfo != null);

            object[] attributes = fieldInfo.GetCustomAttributes(
                TypeOfLocalizabilityAttribute, // type of localizability
                true
                );                             // inherit

            if (attributes.Length == 0)
            {
                // didn't find it.
                return;
            }
            else
            {
                Debug.Assert(attributes.Length == 1, "Should have only 1 localizability attribute");
                localizability = (LocalizabilityAttribute)attributes[0];
            }
        }
        // Token: 0x06006EB8 RID: 28344 RVA: 0x001FD1C4 File Offset: 0x001FB3C4
        private void GetLocalizabilityForElementNode(BamlStartElementNode node, out LocalizabilityAttribute localizability, out string formattingTag)
        {
            localizability = null;
            formattingTag  = null;
            string assemblyName = node.AssemblyName;
            string typeFullName = node.TypeFullName;
            ElementLocalizability elementLocalizability = this._resolver.GetElementLocalizability(assemblyName, typeFullName);
            LocalizabilityGroup   localizabilityComment = this._resolver.GetLocalizabilityComment(node, "$Content");

            if (localizabilityComment != null)
            {
                localizability = localizabilityComment.Override(elementLocalizability.Attribute);
            }
            else
            {
                localizability = elementLocalizability.Attribute;
            }
            formattingTag = elementLocalizability.FormattingTag;
        }
        // Token: 0x06006E2A RID: 28202 RVA: 0x001FB770 File Offset: 0x001F9970
        public override LocalizabilityAttribute GetPropertyLocalizability(string assembly, string className, string property)
        {
            if (this._externalResolver == null || assembly == null || assembly.Length == 0 || className == null || className.Length == 0 || property == null || property.Length == 0)
            {
                return(this.DefaultAttribute);
            }
            string key = className + ":" + property;

            if (this._propertyAttributeTable.ContainsKey(key))
            {
                return(this._propertyAttributeTable[key]);
            }
            LocalizabilityAttribute localizabilityAttribute = this._externalResolver.GetPropertyLocalizability(assembly, className, property);

            if (localizabilityAttribute == null)
            {
                localizabilityAttribute = this.DefaultAttribute;
            }
            this._propertyAttributeTable[key] = localizabilityAttribute;
            return(localizabilityAttribute);
        }
        private void GetLocalizabilityForPropertyNode(
            BamlStartComplexPropertyNode node,
            out LocalizabilityAttribute localizability
            )
        {
            localizability = null;

            string assemblyName      = node.AssemblyName;
            string className         = node.OwnerTypeFullName;
            string propertyLocalName = node.PropertyName;

            if (className == null || className.Length == 0)
            {
                // class name can be empty or null. For example, <Set PropertyPath="...">
                // We will use the parent node's value.
                string formattingTag;
                GetLocalizabilityForElementNode((BamlStartElementNode)node.Parent, out localizability, out formattingTag);
                return;
            }

            LocalizabilityGroup comment = _resolver.GetLocalizabilityComment(
                (BamlStartElementNode)node.Parent,
                node.PropertyName
                );

            localizability = _resolver.GetPropertyLocalizability(
                assemblyName,
                className,
                propertyLocalName
                );

            if (comment != null)
            {
                localizability = comment.Override(localizability);
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="formattingTag">formatting tag, give a non-empty value to indicate that the class is formatted inline</param>
 /// <param name="attribute">LocalizabilityAttribute for the class</param>
 public ElementLocalizability(string formattingTag, LocalizabilityAttribute attribute)
 {
     _formattingTag = formattingTag;
     _attribute     = attribute;
 }
        // Token: 0x06006EB5 RID: 28341 RVA: 0x001FCDA0 File Offset: 0x001FAFA0
        internal BamlLocalizableResource BuildFromNode(BamlLocalizableResourceKey key, BamlTreeNode node)
        {
            if (node.Formatted)
            {
                return(null);
            }
            BamlLocalizableResource bamlLocalizableResource = null;
            LocalizabilityAttribute localizabilityAttribute = null;
            BamlStartElementNode    node2 = null;
            string       localName        = null;
            BamlNodeType nodeType         = node.NodeType;

            if (nodeType != BamlNodeType.StartElement)
            {
                if (nodeType != BamlNodeType.Property)
                {
                    if (nodeType != BamlNodeType.LiteralContent)
                    {
                        Invariant.Assert(false);
                    }
                    else
                    {
                        string text;
                        this.GetLocalizabilityForElementNode((BamlStartElementNode)node.Parent, out localizabilityAttribute, out text);
                        node2     = (BamlStartElementNode)node.Parent;
                        localName = "$Content";
                    }
                }
                else
                {
                    BamlStartComplexPropertyNode bamlStartComplexPropertyNode = (BamlStartComplexPropertyNode)node;
                    if (LocComments.IsLocCommentsProperty(bamlStartComplexPropertyNode.OwnerTypeFullName, bamlStartComplexPropertyNode.PropertyName) || LocComments.IsLocLocalizabilityProperty(bamlStartComplexPropertyNode.OwnerTypeFullName, bamlStartComplexPropertyNode.PropertyName))
                    {
                        return(null);
                    }
                    this.GetLocalizabilityForPropertyNode(bamlStartComplexPropertyNode, out localizabilityAttribute);
                    localName = bamlStartComplexPropertyNode.PropertyName;
                    node2     = (BamlStartElementNode)node.Parent;
                }
            }
            else
            {
                node2 = (BamlStartElementNode)node;
                string text;
                this.GetLocalizabilityForElementNode(node2, out localizabilityAttribute, out text);
                localName = "$Content";
            }
            localizabilityAttribute = this.CombineAndPropagateInheritanceValues(node as ILocalizabilityInheritable, localizabilityAttribute);
            string content = null;

            if (localizabilityAttribute.Category != LocalizationCategory.NeverLocalize && localizabilityAttribute.Category != LocalizationCategory.Ignore && this.TryGetContent(key, node, out content))
            {
                bamlLocalizableResource            = new BamlLocalizableResource();
                bamlLocalizableResource.Readable   = (localizabilityAttribute.Readability == Readability.Readable);
                bamlLocalizableResource.Modifiable = (localizabilityAttribute.Modifiability == Modifiability.Modifiable);
                bamlLocalizableResource.Category   = localizabilityAttribute.Category;
                bamlLocalizableResource.Content    = content;
                bamlLocalizableResource.Comments   = this._resolver.GetStringComment(node2, localName);
            }
            return(bamlLocalizableResource);
        }
        /// <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);
        }
        // Token: 0x06006EB9 RID: 28345 RVA: 0x001FD22C File Offset: 0x001FB42C
        private void GetLocalizabilityForPropertyNode(BamlStartComplexPropertyNode node, out LocalizabilityAttribute localizability)
        {
            localizability = null;
            string assemblyName      = node.AssemblyName;
            string ownerTypeFullName = node.OwnerTypeFullName;
            string propertyName      = node.PropertyName;

            if (ownerTypeFullName == null || ownerTypeFullName.Length == 0)
            {
                string text;
                this.GetLocalizabilityForElementNode((BamlStartElementNode)node.Parent, out localizability, out text);
                return;
            }
            LocalizabilityGroup localizabilityComment = this._resolver.GetLocalizabilityComment((BamlStartElementNode)node.Parent, node.PropertyName);

            localizability = this._resolver.GetPropertyLocalizability(assemblyName, ownerTypeFullName, propertyName);
            if (localizabilityComment != null)
            {
                localizability = localizabilityComment.Override(localizability);
            }
        }
        /// <summary>
        /// build a localizable resource from a baml tree node
        /// </summary>
        internal BamlLocalizableResource BuildFromNode(BamlLocalizableResourceKey key, BamlTreeNode node)
        {
            if (node.Formatted)
            {
                // the content of the node has been formatted to be part of
                // parents' content, so no need to create a seperate entry for the
                // element
                return(null);
            }

            BamlLocalizableResource resource       = null;
            LocalizabilityAttribute localizability = null;
            string formattingTag;

            //
            // variable controling what comments gets applied
            //
            BamlStartElementNode commentNode = null;           // node containing comment
            string commentTargetName         = null;           // the target of the comment, e.g. $Content, FontSize, etc.

            //
            // step 1: Get the localizability attribute from the source files
            //
            switch (node.NodeType)
            {
            case BamlNodeType.StartElement:
            {
                // For element
                commentNode = (BamlStartElementNode)node;
                GetLocalizabilityForElementNode(commentNode, out localizability, out formattingTag);
                commentTargetName = BamlConst.ContentSuffix;
                break;
            }

            case BamlNodeType.LiteralContent:
            {
                // For literal content, get the attribute from parent element
                GetLocalizabilityForElementNode((BamlStartElementNode)node.Parent, out localizability, out formattingTag);

                commentNode       = (BamlStartElementNode)node.Parent;
                commentTargetName = BamlConst.ContentSuffix;
                break;
            }

            case BamlNodeType.Property:
            {
                BamlStartComplexPropertyNode propertyNode = (BamlStartComplexPropertyNode)node;
                if (LocComments.IsLocCommentsProperty(propertyNode.OwnerTypeFullName, propertyNode.PropertyName) ||
                    LocComments.IsLocLocalizabilityProperty(propertyNode.OwnerTypeFullName, propertyNode.PropertyName)
                    )
                {
                    // skip Localization.Comments and Localization.Attributes properties. They aren't localizable
                    return(null);
                }

                // For property
                GetLocalizabilityForPropertyNode(propertyNode, out localizability);

                commentTargetName = propertyNode.PropertyName;
                commentNode       = (BamlStartElementNode)node.Parent;
                break;
            }

            default:
            {
                Invariant.Assert(false);     // no localizable resource for such node
                break;
            }
            }

            //
            // Step 2: Find out the inheritance value
            //

            // The node participates in localizability inheritance
            // let's fill things in
            localizability = CombineAndPropagateInheritanceValues(
                node as ILocalizabilityInheritable,
                localizability
                );

            //
            // Step 3: We finalized the localizability values. We now apply.
            //
            string content = null;

            if (localizability.Category != LocalizationCategory.NeverLocalize &&
                localizability.Category != LocalizationCategory.Ignore &&
                TryGetContent(key, node, out content))
            {
                // we only create one if it is localizable
                resource            = new BamlLocalizableResource();
                resource.Readable   = (localizability.Readability == Readability.Readable);
                resource.Modifiable = (localizability.Modifiability == Modifiability.Modifiable);
                resource.Category   = localizability.Category;
                // continue to fill in content.
                resource.Content  = content;
                resource.Comments = _resolver.GetStringComment(commentNode, commentTargetName);
            }

            // return the resource
            return(resource);
        }
 /// <summary> 
 /// Constructor
 /// </summary> 
 /// <param name="formattingTag">formatting tag, give a non-empty value to indicate that the class is formatted inline</param> 
 /// <param name="attribute">LocalizabilityAttribute for the class</param>
 public ElementLocalizability(string formattingTag, LocalizabilityAttribute attribute) 
 {
     _formattingTag = formattingTag;
     _attribute     = attribute;
 } 
        // 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);
            }
        }