Пример #1
0
        /// <summary>
        /// Parses the boolean value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="value">if set to <c>true</c> [value].</param>
        /// <returns>
        /// True, if the parse was successful, otherwise False.
        /// </returns>
        /// <example>
        ///   <code>
        /// mSessionReusable = true;
        /// ConfigurationAccessHelper.ParseBooleanValue(pi.PropertyItems, "SessionReusable", ref mSessionReusable);
        ///   </code>
        ///   </example>
        public static bool ParseBooleanValue(CategoryPropertyItems root, String entryId, ref bool value)
        {
            bool result = false;

            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root, entryId);

            if (pi != null)
            {
                result = bool.TryParse(pi.EntryValue, out value);
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Parses the string value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="value">The value.</param>
        /// <returns>
        /// True, if the parse was successful, otherwise False.
        /// </returns>
        /// <example>
        ///   <code>
        /// ConfigurationAccessHelper.ParseStringValue(UpdateConfiguration.Settings.CategoryPropertyItems, DOWNLOAD_FOLDER, ref mDownloadFolder);
        ///   </code>
        ///   </example>
        public static bool ParseStringValue(CategoryPropertyItems root, String entryId, ref string value)
        {
            bool result = false;

            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root, entryId);

            if (pi != null)
            {
                value  = pi.EntryValue;
                result = true;
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Parses the enum value.
        /// </summary>
        /// <typeparam name="TEnum">The type of the enum.</typeparam>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static bool ParseEnumValue <TEnum>(CategoryPropertyItems root, string entryId, ref TEnum value) where TEnum : struct
        {
            bool result = false;

            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root, entryId);

            if (pi != null)
            {
                try
                {
                    value  = (TEnum)Enum.Parse(typeof(TEnum), pi.EntryValue, true);
                    result = true;
                }
                catch (Exception) { }
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Parses the float value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="minValue">The min value.</param>
        /// <param name="maxValue">The max value.</param>
        /// <param name="value">The value.</param>
        /// <returns>
        /// True, if the parse was successful, otherwise False.
        /// </returns>
        /// <exception cref="InvalidConfigurationValueException">
        /// </exception>
        public static bool ParseFloatValue(CategoryPropertyItems root, String entryId, float minValue, float maxValue, ref float value)
        {
            bool result             = false;
            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root, entryId);

            if (pi != null)
            {
                result = float.TryParse(pi.EntryValue, out value);
                if (result)
                {
                    if (value < minValue)
                    {
                        throw new InvalidConfigurationValueException(String.Format("Minimum value ({0}) is out of range ({1}) for item: {2}", minValue, result, entryId));
                    }
                    if (value > maxValue)
                    {
                        throw new InvalidConfigurationValueException(String.Format("Maximum value ({0}) is out of range ({1}) for item: {2}", maxValue, result, entryId));
                    }
                }
            }
            return(result);
        }