Beispiel #1
0
        public static bool TryGet <T>(string keyName, out T value)
        {
            AdmSettings setting = GetAdmSettingByKey(keyName);

            try
            {
                if (!string.IsNullOrWhiteSpace(setting?.StringValue))
                {
                    value = (T)Convert.ChangeType(setting.StringValue, typeof(T));
                    return(true);
                }
                else if (setting?.NumValue != null)
                {
                    value = (T)Convert.ChangeType(setting.NumValue, typeof(T));
                    return(true);
                }
                else if (setting?.DateValue != null)
                {
                    value = (T)Convert.ChangeType(setting.DateValue, typeof(T));
                    return(true);
                }
            }
            catch
            {
            }

            value = default(T);
            return(false);
        }
Beispiel #2
0
        public static T Get <T>(string keyName)
        {
            AdmSettings setting = GetAdmSettingByKey(keyName);

            if (!string.IsNullOrWhiteSpace(setting?.StringValue))
            {
                return((T)Convert.ChangeType(setting.StringValue, typeof(T)));
            }
            else if (setting?.NumValue != null)
            {
                return((T)Convert.ChangeType(setting.NumValue, typeof(T)));
            }
            else if (setting?.DateValue != null)
            {
                return((T)Convert.ChangeType(setting.DateValue, typeof(T)));
            }

            return(default(T));
        }
Beispiel #3
0
        private static AdmSettings GetSingleSetting(List <AdmSettings> settings)
        {
            AdmSettings setting = new AdmSettings();

            if (string.IsNullOrWhiteSpace(ConfigVersion) || settings.Where(x => x.Version == ConfigVersion).Count() == 0)
            {
                setting = settings.FirstOrDefault(x => string.IsNullOrWhiteSpace(x.Version));
            }
            else
            {
                foreach (AdmSettings set in settings)
                {
                    string[] versions = set?.Version?.Split(new char[] { ',' });
                    if (versions != null && versions.Contains(ConfigVersion))
                    {
                        setting = set;
                    }
                }
            }

            return(setting);
        }