private object Get(string key, Type targetType = null, object defaultValue = null, SerializationMode serializationMode = SerializationMode.Xml) { try { if (targetType == null) { targetType = ConvertSettingsType(Check.TryCatch <SettingsType, Exception>(() => settingsStore.GetPropertyType(collectionPath, key))); } object result = null; if (targetType.IsEnum) { targetType = typeof(int); } if (targetType == typeof(bool)) { result = settingsStore.GetBoolean(collectionPath, key, Convert.ToBoolean(defaultValue)); } else if (targetType == typeof(string)) { result = settingsStore.GetString(collectionPath, key, defaultValue as string); } else if (targetType == typeof(int)) { result = settingsStore.GetInt32(collectionPath, key, Convert.ToInt32(defaultValue)); } else { if (settingsStore.PropertyExists(collectionPath, key)) { if (serializationMode == SerializationMode.Xml) { string xmlContent = settingsStore.GetString(collectionPath, key); var serializer = new XmlSerializer(targetType); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xmlContent)); var res = serializer.Deserialize(ms); return(res); } else { var ms = settingsStore.GetMemoryStream(collectionPath, key); if (ms != null) { var serializer = new BinaryFormatter(); result = serializer.Deserialize(ms); } } } } return(result ?? defaultValue); } catch (Exception) { return(defaultValue); } }