Exemple #1
0
        /// <summary>
        /// Bind a property to localized values.
        /// </summary>
        public string BindCustomValue <T>(T item,
                                          string property,
                                          Dictionary <string, string> values,
                                          string culture = null)
        {
            culture = culture ?? DefaultCulture;
            var boundValue = new BoundLocalizationObject
            {
                Item         = item,
                PropertyInfo = item.GetType().GetTypeInfo().GetProperty(property),
                Values       = values
            };
            var currentValue = GetLocalValue(boundValue, culture);

            _customBoundObjects.Add(boundValue);
            boundValue.SetValue(currentValue);
            return(currentValue);
        }
Exemple #2
0
 private string GetLocalValue(BoundLocalizationObject boundObject, string culture)
 {
     if (boundObject.Values != null)
     {
         if (boundObject.Values.ContainsKey(culture))
         {
             return(boundObject.Values[culture]);
         }
         if (boundObject.Values.Values != null && boundObject.Values.Values.Any())
         {
             return(boundObject.Values.Values.FirstOrDefault());
         }
     }
     _logger?.Log(nameof(LocalizationManager),
                  $"Local localization values not found for '{boundObject.Item}'",
                  LogRecordTypes.Debug);
     return(null);
 }
Exemple #3
0
        /// <inheritdoc />
        public string BindValue <T>(T item, Expression <Func <T, object> > property, string key, string culture = null)
        {
            var currentValue = GetValue(key, culture);
            var propertyName = ExpressionHelper.GetMemberName(property);
            var boundValue   = new BoundLocalizationObject
            {
                Item         = item,
                PropertyInfo = item.GetType().GetTypeInfo().GetProperty(propertyName)
            };

            if (!_boundObjects.ContainsKey(key))
            {
                _boundObjects.TryAdd(key, new List <BoundLocalizationObject>());
            }
            if (_boundObjects.TryGetValue(key, out var objects))
            {
                objects.Add(boundValue);
            }
            boundValue.SetValue(currentValue);
            return(currentValue);
        }