Skip to content

Commit

Permalink
Add try catch to DisplayFunction.Invoke()
Browse files Browse the repository at this point in the history
  • Loading branch information
gave92 committed Nov 8, 2023
1 parent 6ecfc27 commit a68c0b2
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/Files.App/ViewModels/Properties/Items/FileProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private IValueConverter GetConverter()
/// Converts the property to a string to be displayed
/// </summary>
/// <returns></returns>
private string ConvertToString()
private string? ConvertToString()
{
// Don't attempt any convert null values
if (Value is null)
Expand All @@ -227,28 +227,27 @@ private string ConvertToString()

if (EnumeratedList is not null)
{
var value = "";
int valueKey;

try
{
valueKey = Convert.ToInt32(Value);
return EnumeratedList.TryGetValue(Convert.ToInt32(Value), out var value) ?
value.GetLocalizedResource() : null;
}
catch
{
if (!int.TryParse(Value.ToString(), out valueKey))
{
return null;
}
return null;
}

return EnumeratedList.TryGetValue(valueKey, out value) ? value.GetLocalizedResource() : null;

}

if (DisplayFunction is not null)
{
return DisplayFunction.Invoke(Value);
try
{
return DisplayFunction.Invoke(Value);
}
catch
{
return null;
}
}

if (Converter is not null)
Expand Down

0 comments on commit a68c0b2

Please sign in to comment.