Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new localized value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c>.</exception>
        internal static void InternalAddLocalizedValue(LocalizedValue value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (_localizedValuesPurgeCount > PurgeLimit)
            {
                // Remove localized values the owners of which have been garbage collected

                lock (LocalizedValues)
                {
                    List<LocalizedProperty> keys = null;

                    foreach (var item in LocalizedValues.Keys)
                    {
                        if (false == item.IsAlive)
                        {
                            if (keys == null)
                            {
                                keys = new List<LocalizedProperty>();
                            }

                            keys.Add(item);
                        }
                    }

                    if (keys != null)
                    {
                        foreach (var key in keys)
                        {
                            LocalizedValues.Remove(key);
                        }
                    }

                    _localizedValuesPurgeCount = 0;
                }
            }

            lock (LocalizedValues)
            {
                var count = LocalizedValues.Count;

                LocalizedValues[value.Property] = value;

                if (count < LocalizedValues.Count)
                {
                    // A new value has been added

                    _localizedValuesPurgeCount++;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a new localized value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is <c>null</c>.</exception>
        public static void AddLocalizedValue(LocalizedValue value)
        {
            InternalAddLocalizedValue(value);

            // Update the value initially
            value.UpdateValue();
        }