Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalizedValue"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        protected LocalizedValue(LocalizedProperty property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            Property = property;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceLocalizedValue"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="resourceKey">The resource key.</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="resourceKey"/> is null or empty.</exception>
        public ResourceLocalizedValue(LocalizedProperty property, string resourceKey)
            : base(property)
        {
            if (string.IsNullOrEmpty(resourceKey))
            {
                throw new ArgumentNullException("resourceKey");
            }

            _resourceKey = resourceKey;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodLocalizedValue"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="method">The method.</param>
        /// <param name="parameter">The parameter to pass to the method.</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="method"/> is null.</exception>
        public MethodLocalizedValue(LocalizedProperty property, LocalizationCallback method, object parameter)
            : base(property)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            _method = method;

            _parameter = parameter;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormattedLocalizedValue"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="resourceKey">The resource key.</param>
        /// <param name="args">The args.</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="resourceKey"/> is null or empty.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="args"/> is null.</exception>
        public ResourceFormattedLocalizedValue(
            LocalizedProperty property,
            string resourceKey,
            params object[] args
            )
            : base(property, resourceKey)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            _args = args;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormattedLocalizedValue"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="resourceKey">The resource key.</param>
        /// <param name="args">The args.</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="resourceKey"/> is null or empty.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="args"/> is null.</exception>
        public ResourceFormattedLocalizedValue(
            LocalizedProperty property,
            string resourceKey,
            params object[] args
            )
            : base(property, resourceKey)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            _args = args;
        }
Пример #6
0
 LocalizedValue CreateLocalizedValue(LocalizedProperty property)
 {
     if (Callback != null && Callback.GetCallback() != null)
     {
         return(new MethodLocalizedValue(property, Callback.GetCallback(), CallbackParameter));
     }
     else if (string.IsNullOrEmpty(ResourceKey))
     {
         return(null);
     }
     else
     {
         return(new ResourceLocalizedValue(property, ResourceKey));
     }
 }
Пример #7
0
        /// <summary>
        /// Checks if binding localization can be used on the specified property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        ///     <c>true</c> binding localization can be used; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        internal static void CheckPropertySupported(LocalizedProperty property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (property.GetValueType() == typeof(string) || property.GetValueType() == typeof(object))
            {
                // The property is supported
            }
            else
            {
                throw new InvalidOperationException("Only properties of type 'System.String' and 'System.Object' are supported.");
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormattedLocalizedValue"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="formatString">The format string.</param>
        /// <param name="args">The args.</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="formatString"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="args"/> is null.</exception>
        public FormattedLocalizedValue(LocalizedProperty property, string formatString, params object[] args)
            : base(property)
        {
            if (formatString == null)
            {
                throw new ArgumentNullException("formatString");
            }

            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            _formatString = formatString;

            _args = args;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormattedLocalizedValue"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="formatString">The format string.</param>
        /// <param name="args">The args.</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="formatString"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="args"/> is null.</exception>
        public FormattedLocalizedValue(LocalizedProperty property, string formatString, params object[] args)
            : base(property)
        {
            if (formatString == null)
            {
                throw new ArgumentNullException("formatString");
            }

            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            _formatString = formatString;

            _args = args;
        }
Пример #10
0
        /// <summary>
        /// Removes any localized value associated with the specified property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is <c>null</c>.</exception>
        /// <remarks>
        /// This method remvoes the property from the list of properties updated automatically when the
        /// current culture changes. The current value of the property remains untouched.
        /// </remarks>
        public static void RemoveLocalizedValue(LocalizedProperty property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            lock (_localizedValues)
            {
                _localizedValues.Remove(property);
            }
        }
Пример #11
0
 /// <summary>
 /// Assigns a value that is produced by a callback.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="method">The callback method.</param>
 /// <param name="parameter">The parameter to pass to the callback method.</param>
 /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="method"/> is null.</exception>
 /// <remarks>
 /// The method will be called once to set the initial value of the property and each
 /// time the current culture changes.
 /// </remarks>
 public static void SetCallbackValue(this LocalizedProperty property, LocalizationCallback method, object parameter)
 {
     AddLocalizedValue(new MethodLocalizedValue(property, method, parameter));
 }
Пример #12
0
 /// <summary>
 /// Assigns a formated value to the specified property. The format string is kept
 /// in resources.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="resourceKey">The resource key.</param>
 /// <param name="args">The args.</param>
 /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="resourceKey"/> is null or empty.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="args"/> is null.</exception>
 public static void SetResourceFormattedValue(this LocalizedProperty property, string resourceKey, params object[] args)
 {
     AddLocalizedValue(new ResourceFormattedLocalizedValue(property, resourceKey, args));
 }
Пример #13
0
 /// <summary>
 /// Assigns a formated value to the specified property.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="formatString">The format string.</param>
 /// <param name="args">The args.</param>
 /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="formatString"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="args"/> is null.</exception>
 public static void SetFormattedValue(this LocalizedProperty property, string formatString, params object[] args)
 {
     AddLocalizedValue(new FormattedLocalizedValue(property, formatString, args));
 }
Пример #14
0
 /// <summary>
 /// Assigns a resource value to the specified localized property.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <param name="resourceKey">The resource key.</param>
 /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="resourceKey"/> is null or empty.</exception>
 public static void SetResourceValue(this LocalizedProperty property, string resourceKey)
 {
     AddLocalizedValue(new ResourceLocalizedValue(property, resourceKey));
 }
Пример #15
0
 LocalizedValue CreateLocalizedValue(LocalizedProperty property)
 {
     if (Callback != null && Callback.GetCallback() != null)
     {
         return new MethodLocalizedValue(property, Callback.GetCallback(), CallbackParameter);
     }
     else if (string.IsNullOrEmpty(ResourceKey))
     {
         return null;
     }
     else
     {
         return new ResourceLocalizedValue(property, ResourceKey);
     }
 }
Пример #16
0
 /// <summary>
 /// Stops localizing the property. Does not clear the current value of the property.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
 public static void Clear(this LocalizedProperty property)
 {
     RemoveLocalizedValue(property);
 }
        /// <summary>
        /// Checks if binding localization can be used on the specified property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <returns>
        /// 	<c>true</c> binding localization can be used; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="property"/> is null.</exception>
        internal static void CheckPropertySupported(LocalizedProperty property)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (property.GetValueType() == typeof(string) || property.GetValueType() == typeof(object))
            {
                // The property is supported
            }
            else
            {
                throw new InvalidOperationException("Only properties of type 'System.String' and 'System.Object' are supported.");
            }
        }