Don't throw NullReferenceException and instead use nullable type

This commit is contained in:
Jaex 2022-07-31 15:19:00 +03:00
parent 61d69f8399
commit 50ce50eae1
2 changed files with 5 additions and 11 deletions

View file

@ -111,17 +111,11 @@ public static float GetCursorSizeMultiplier()
{
float sizeMultiplier = 1f;
try
{
int cursorSize = RegistryHelpers.GetValueDWord(@"SOFTWARE\Microsoft\Accessibility", "CursorSize");
int? cursorSize = RegistryHelpers.GetValueDWord(@"SOFTWARE\Microsoft\Accessibility", "CursorSize");
if (cursorSize > 1)
{
sizeMultiplier = 1f + ((cursorSize - 1) * 0.5f);
}
}
catch
if (cursorSize != null && cursorSize > 1)
{
sizeMultiplier = 1f + (((int)cursorSize - 1) * 0.5f);
}
return sizeMultiplier;

View file

@ -107,9 +107,9 @@ public static string GetValueString(string path, string name = null, RegistryHiv
return GetValue(path, name, root, view) as string;
}
public static int GetValueDWord(string path, string name = null, RegistryHive root = RegistryHive.CurrentUser, RegistryView view = RegistryView.Default)
public static int? GetValueDWord(string path, string name = null, RegistryHive root = RegistryHive.CurrentUser, RegistryView view = RegistryView.Default)
{
return (int)GetValue(path, name, root, view);
return (int?)GetValue(path, name, root, view);
}
public static bool CheckStringValue(string path, string name = null, string value = null, RegistryHive root = RegistryHive.CurrentUser, RegistryView view = RegistryView.Default)