Skip to content

Commit 01970f8

Browse files
Copilotrthanga1
andauthored
Fix CodeQL alerts in dropdown spinner and resource lookup
Agent-Logs-Url: https://github.com/trimble-oss/modus-mobile-maui-components/sessions/dd073a81-d003-484c-b344-dbbd050213b9 Co-authored-by: rthanga1 <60956922+rthanga1@users.noreply.github.com>
1 parent e8b63a8 commit 01970f8

3 files changed

Lines changed: 22 additions & 18 deletions

File tree

Trimble.Modus.Components/Controls/DropDown/TMDropDown.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private void OnSelected(object sender, SelectedItemChangedEventArgs e)
201201
var newItem = e.SelectedItem;
202202
var newIndex = e.SelectedItemIndex;
203203

204-
// Always update (even if newItem is null that represents clearing)
204+
// Always update (even if newItem is null that represents clearing)
205205
SelectedItem = newItem;
206206
SelectedIndex = newIndex;
207207

@@ -332,10 +332,10 @@ private void UpdateListBorderHeight(IEnumerable items)
332332

333333
if (itemCount < 4)
334334
{
335-
desiredHeight = itemCount * 56;
336-
margin = new Thickness(0, ((itemCount - 1) * 56) + 4, 10, 0);
335+
desiredHeight = itemCount * 56.0;
336+
margin = new Thickness(0, ((itemCount - 1) * 56.0) + 4.0, 10, 0);
337337
#if WINDOWS
338-
margin = new Thickness(0, ((itemCount - 1) * 56) + 30, 10, 0);
338+
margin = new Thickness(0, ((itemCount - 1) * 56.0) + 30.0, 10, 0);
339339
#endif
340340
}
341341
}

Trimble.Modus.Components/Controls/TMSpinner/TMSpinner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static void OnSpinnerSizeChanged(BindableObject bindable, object oldValu
103103
{
104104
if (bindable is TMSpinner tmSpinner)
105105
{
106-
Console.WriteLine("Spinner Size Changed", (Size)newValue);
106+
Console.WriteLine($"Spinner Size Changed: {(Size)newValue}");
107107
switch ((Size)newValue)
108108
{
109109
case Size.XSmall:

Trimble.Modus.Components/Helpers/ResourceDictionary.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ public static class ResourcesDictionary
44
{
55
public static Color GetColor(string styleKey)
66
{
7-
if (Application.Current.Resources.ContainsKey(styleKey))
7+
if (Application.Current?.Resources is ResourceDictionary resources &&
8+
resources.TryGetValue(styleKey, out var applicationResource) &&
9+
applicationResource is Color applicationColor)
810
{
9-
return Application.Current.Resources[styleKey] as Color;
11+
return applicationColor;
1012
}
11-
else
13+
14+
ResourceDictionary style = new Styles.LightThemeColors();
15+
if (Application.Current?.RequestedTheme == AppTheme.Dark)
16+
{
17+
style = new Styles.DarkThemeColors();
18+
}
19+
20+
try
21+
{
22+
return style[styleKey] as Color ?? Colors.Transparent;
23+
}
24+
catch (KeyNotFoundException)
1225
{
13-
ResourceDictionary style = new Styles.LightThemeColors();
14-
if (Application.Current.RequestedTheme == AppTheme.Dark)
15-
{
16-
style = new Styles.DarkThemeColors();
17-
}
18-
if (style.ContainsKey(styleKey))
19-
{
20-
return style[styleKey] as Color;
21-
}
26+
return Colors.Transparent;
2227
}
23-
return Colors.Transparent;
2428
}
2529
}

0 commit comments

Comments
 (0)