コード例 #1
0
        public override string ResolveFormattingTagToClass(string formattingTag)
        {            
            // go through the cache to find the mapping
            foreach (KeyValuePair<string, ElementLocalizability> pair in _classAttributeTable)
            {
                if (pair.Value.FormattingTag == formattingTag)
                    return pair.Key;
            }

            string className = null;
            if (_externalResolver != null)
            {
                // it is a formatting tag not resolved before. need to ask for client's help
                className = _externalResolver.ResolveFormattingTagToClass(formattingTag);
                if (!string.IsNullOrEmpty(className))
                {
                    // cache the result
                    if (_classAttributeTable.ContainsKey(className))
                    {
                        _classAttributeTable[className].FormattingTag = formattingTag;
                    }
                    else
                    {
                        _classAttributeTable[className] = new ElementLocalizability(formattingTag, null); 
                    }
                }
            }
            
            return className;
        }
コード例 #2
0
        /// <summary>
        /// Return the localizability of an element to the BamlLocalizer
        /// </summary>
        public override ElementLocalizability GetElementLocalizability(
            string assembly,
            string className
            )
        {
            ElementLocalizability loc = new ElementLocalizability();

            Type type = GetType(assembly, className);
            if (type != null)
            {
                // We found the type, now try to get the localizability attribte from the type
                loc.Attribute = GetLocalizabilityFromType(type);
            }

            // fill in the formatting tag
            int index = Array.IndexOf(FormattedElements, className);
            if (index >= 0)
            {
                loc.FormattingTag = FormattingTag[index];
            }

            return loc;
        }
コード例 #3
0
 //--------------------------------------
 // BamlLocalizabilityResolver interface
 //--------------------------------------   
 public override ElementLocalizability GetElementLocalizability(string assembly, string className)
 {
     if ( _externalResolver == null
       || assembly == null  || assembly.Length == 0
       || className == null || className.Length == 0)
     {
         // return the default value 
         return new ElementLocalizability(
             null,
             DefaultAttribute
             );
     }
     
     
     if (_classAttributeTable.ContainsKey(className))
     {
         // return cached value
         return _classAttributeTable[className];
     }
     else
     {
         ElementLocalizability loc  = _externalResolver.GetElementLocalizability(assembly, className);
         if (loc == null || loc.Attribute == null)
         {
             loc = new ElementLocalizability(
                 null,
                 DefaultAttribute
                 );
         }
         _classAttributeTable[className] = loc;
         return loc;
     }
 }