Skip to content

Commit 8a341bc

Browse files
authored
Fix null detection of file extension (#778)
1 parent 0735487 commit 8a341bc

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

Files/View Models/InteractionViewModel.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,23 @@ public bool IsPageTypeNotHome
4949
public void CheckForImage()
5050
{
5151
//check if the selected item is an image file
52-
try
53-
{
54-
string ItemExtension = (App.CurrentInstance.ContentPage as BaseLayout).SelectedItem.FileExtension;
52+
string ItemExtension = (App.CurrentInstance.ContentPage as BaseLayout).SelectedItem.FileExtension;
5553

56-
if (!string.IsNullOrEmpty(ItemExtension)
57-
&& ItemExtension.Equals(".png", StringComparison.OrdinalIgnoreCase)
58-
|| ItemExtension.Equals(".jpg", StringComparison.OrdinalIgnoreCase)
59-
|| ItemExtension.Equals(".bmp", StringComparison.OrdinalIgnoreCase)
60-
|| ItemExtension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
54+
if (!string.IsNullOrEmpty(ItemExtension))
55+
{
56+
if (ItemExtension.Equals(".png", StringComparison.OrdinalIgnoreCase)
57+
|| ItemExtension.Equals(".jpg", StringComparison.OrdinalIgnoreCase)
58+
|| ItemExtension.Equals(".bmp", StringComparison.OrdinalIgnoreCase)
59+
|| ItemExtension.Equals(".jpeg", StringComparison.OrdinalIgnoreCase))
6160
{
6261
// Since item is an image, set the IsSelectedItemImage property to true
6362
App.InteractionViewModel.IsSelectedItemImage = true;
64-
}
65-
else
66-
{
67-
// Since item is not an image, set the IsSelectedItemImage property to false
68-
App.InteractionViewModel.IsSelectedItemImage = false;
63+
return;
6964
}
7065
}
71-
catch (Exception) { }
66+
67+
// Since item is not an image, folder or file without extension, set the IsSelectedItemImage property to false
68+
App.InteractionViewModel.IsSelectedItemImage = false;
7269
}
7370
}
7471
}

0 commit comments

Comments
 (0)