public void AppSettingsDataConverterTest()
        {
            IDataConverter dataConverter = new AppSettingsDataConverter();
            ConfigTest1    configTest1   = (ConfigTest1)dataConverter.Parse(typeof(ConfigTest1), Constant.AppSettingsDataConverterTestValue1);

            Assert.IsNotNull(configTest1);
            Assert.AreEqual("127.0.0.1", configTest1.Host);
            Assert.AreEqual(81, configTest1.Port);
        }
Пример #2
0
        public static T GetConfigValue <T>(string key, T defalut = default(T))
        {
            ConfigStorageItem item = ConfigStorageManager.GetConfigStorageItem(key);

            if (item == null)
            {
                return(defalut);
            }
            if (typeof(T) == typeof(string))
            {
                return((T)((object)item.Data));
            }

            IDataConverter dataConverter = DataConverterManager.GetDataConverter(key);

            if (dataConverter == null)
            {
                if (key.EndsWith(".json"))
                {
                    dataConverter = new JsonDataConverter();
                }
                else if (key.EndsWith(".config"))
                {
                    dataConverter = new AppSettingsDataConverter();
                }
                else if (key.EndsWith(".properties"))
                {
                    dataConverter = new PropertiesDataConverter();
                }
                else
                {
                    dataConverter = new DefalutDataConverter();
                }
            }
            return((T)dataConverter.Parse(typeof(T), item.Data));
        }