public T GetSettings <T>(TSETT context) where T : new() { foreach (var settingsPropertyValue in SetRepo.GetPropertyValues(context, GetSettingsProperties(null, typeof(T), SettingsPropertyName.Root, null, context))) { PropertyInfo SettAccessor = settingsPropertyValue.SettingsProperty.InternalContext["__SettAccessor"] as PropertyInfo; object obj = ObjDict.Get(settingsPropertyValue.SettingsProperty.PropertyName.Path, context); SettAccessor.SetValue(obj, settingsPropertyValue.PropertyValue); } return((T)ObjDict.Get(SettingsPropertyName.Root, context)); }
public void Basic() { var dictionary = new ObjectDictionary(); Assert.Throws <KeyNotFoundException>(() => dictionary.Get <string>("test")); Assert.Null(dictionary.Get <string>("test", null)); Assert.Equal("default", dictionary.Get <string>("test", "default")); dictionary.Add("test-bool", true); Assert.True(dictionary.Get <bool>("test-bool")); Assert.Throws <InvalidCastException>(() => dictionary.Get <string>("test-bool")); Assert.True(dictionary.Get <bool>("does-not-exist", true)); Assert.False(dictionary.Get <bool>("does-not-exist", false)); dictionary.Add("test-int", 1234); Assert.Equal(1234, dictionary.Get <int>("test-int")); Assert.Throws <InvalidCastException>(() => dictionary.Get <string>("test-bool")); Assert.Equal(1234, dictionary.Get <int>("does-not-exist", 1234)); }