コード例 #1
0
        /// <summary>
        /// Gets boolean value from custom settings dictionary.
        /// </summary>
        /// <param name="config">
        /// The config object - instance of the <see cref="CefConfiguration"/> class.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="defaultValue">
        /// The default value.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/> value.
        /// </returns>
        public static bool GetBooleanValue(this CefConfiguration config, string key, bool defaultValue = false)
        {
            try
            {
                if (config?.CustomSettings != null && config.CustomSettings.ContainsKey(key))
                {
                    var value = config.CustomSettings[key];
                    if (value == null)
                    {
                        return(defaultValue);
                    }

                    if (value is bool boolValue)
                    {
                        return(boolValue);
                    }

                    if (bool.TryParse(value.ToString(), out var result))
                    {
                        return(result);
                    }
                }

                return(defaultValue);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }

            return(defaultValue);
        }
コード例 #2
0
        /// <summary>
        /// Gets string value from custom settings dictionary.
        /// </summary>
        /// <param name="config">
        /// The config object - instance of the <see cref="CefConfiguration"/> class.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="defaultValue">
        /// The default value.
        /// </param>
        /// <returns>
        /// The <see cref="string"/> value.
        /// </returns>
        public static string GetStringValue(this CefConfiguration config, string key, string defaultValue = "")
        {
            try
            {
                if (config?.CustomSettings != null && config.CustomSettings.ContainsKey(key))
                {
                    var value = config.CustomSettings[key];
                    if (value == null)
                    {
                        return(defaultValue);
                    }

                    if (value is string strValue)
                    {
                        return(strValue);
                    }

                    return(value.ToString());
                }

                return(defaultValue);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }

            return(defaultValue);
        }
コード例 #3
0
        /// <summary>
        /// Gets integer value from custom settings dictionary.
        /// </summary>
        /// <param name="config">
        /// The config object - instance of the <see cref="CefConfiguration"/> class.
        /// </param>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="defaultValue">
        /// The default value.
        /// </param>
        /// <returns>
        /// The <see cref="int"/> value.
        /// </returns>
        public static int GetIntegerValue(this CefConfiguration config, string key, int defaultValue = 0)
        {
            try
            {
                if (config?.CustomSettings != null && config.CustomSettings.ContainsKey(key))
                {
                    var value = config.CustomSettings[key];
                    if (value == null)
                    {
                        return(defaultValue);
                    }

                    if (value is int intValue)
                    {
                        return(intValue);
                    }

                    if (int.TryParse(value.ToString(), out var result))
                    {
                        return(result);
                    }
                }

                return(defaultValue);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }

            return(defaultValue);
        }