Skip to content

Commit

Permalink
Update MauiSettingsObjectHelper.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasReitberger committed Oct 22, 2023
1 parent 15c0305 commit 9a2b8a3
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/MauiSettings/Helper/MauiSettingsObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down

0 comments on commit 9a2b8a3

Please sign in to comment.