diff --git a/src/MauiSettings/Helper/MauiSettingsObjectHelper.cs b/src/MauiSettings/Helper/MauiSettingsObjectHelper.cs index 2a66079..649b1dd 100644 --- a/src/MauiSettings/Helper/MauiSettingsObjectHelper.cs +++ b/src/MauiSettings/Helper/MauiSettingsObjectHelper.cs @@ -62,23 +62,30 @@ public static void SetSettingValue(MemberInfo memberInfo, object settings, objec } catch (Exception exc) { - + throw new NotSupportedException($"MauiSettings: The type '{memberInfo.GetType()}' is not supported for the field: {memberInfo.Name}", exc); } - throw new NotSupportedException($"MauiSettings: The type '{memberInfo.GetType()}' is not supported for the field: {memberInfo.Name}"); + } public static Type GetSettingType(MemberInfo memberInfo) { - if (memberInfo is FieldInfo fieldInfo) + try { - return fieldInfo.FieldType; + if (memberInfo is FieldInfo fieldInfo) + { + return fieldInfo.FieldType; + } + if (memberInfo is PropertyInfo propertyInfo) + { + return propertyInfo.PropertyType; + } + else + return default; } - - if (memberInfo is PropertyInfo propertyInfo) + catch (Exception exc) { - return propertyInfo.PropertyType; + throw new NotSupportedException($"MauiSettings: The type '{memberInfo.GetType()}' is not supported for the field: {memberInfo.Name}", exc); } - throw new NotSupportedException($"MauiSettings: The type '{memberInfo.GetType()}' is not supported for the field: {memberInfo.Name}"); } public static object GetTypeDefaultValue(Type type) @@ -107,10 +114,9 @@ public static object GetDefaultValue(MauiSettingBaseAttribute attr, Type setting } return obj; } - return GetTypeDefaultValue(settingType); } - catch (Exception exc) + catch (Exception) { return GetTypeDefaultValue(settingType); } @@ -124,7 +130,6 @@ public static object GetConvertedTypeValue(object setting, Type settingsType) { if (setting?.GetType() == settingsType) return setting; - // return setting.GetType() == typeof(string) ? Activator.CreateInstance(settingsType, new string[] { setting as string }) : Convert.ChangeType(setting, settingsType);