예제 #1
0
        // Methods
        public static TValue GetValue <TValue>(this IServiceConfiguration configuration, string valueKey)
            where TValue : notnull
        {
            #region Contracts

            if (configuration == null)
            {
                throw new ArgumentException(nameof(configuration));
            }
            if (string.IsNullOrEmpty(valueKey) == true)
            {
                throw new ArgumentException(nameof(valueKey));
            }

            #endregion

            // Result
            string valueString = null;

            // ServiceValueString
            var serviceValueString = configuration.GetServiceValueString(valueKey);
            if (string.IsNullOrEmpty(serviceValueString) == false)
            {
                valueString = serviceValueString;
            }
            if (string.IsNullOrEmpty(serviceValueString) == true)
            {
                return(default(TValue));
            }

            // GlobalValueString
            var globalValueString = configuration.GetGlobalValueString(serviceValueString);
            if (string.IsNullOrEmpty(globalValueString) == false)
            {
                valueString = globalValueString;
            }

            // ValueString
            if (string.IsNullOrEmpty(valueString) == true)
            {
                return(default(TValue));
            }
            return((TValue)Convert.ChangeType(valueString, typeof(TValue)));
        }