Esempio n. 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);
        }
Esempio n. 2
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);
        }