Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy OsVersion #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions DesktopToast/Helper/OsVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ public static bool IsEightOrNewer
{
get
{
if (!_isEightOrNewer.HasValue)
{
var ver = GetOsVersionByWmi();
_isEightOrNewer = (ver != null) && (((6 == ver.Major) && (2 <= ver.Minor)) || (7 <= ver.Major));
}

return _isEightOrNewer.Value;
}
}
private static bool? _isEightOrNewer;
private static readonly Lazy<bool> _isEightOrNewer = new Lazy<bool>(GetIsEightOrNewer);

private static bool GetIsEightOrNewer()
{
return (Ver != null) && (((6 == Ver.Major) && (2 <= Ver.Minor)) || (7 <= Ver.Major));
}

/// <summary>
/// Whether OS is Windows 10 or newer
Expand All @@ -36,19 +35,30 @@ public static bool IsTenOrNewer
{
get
{
if (!_isTenOrNewer.HasValue)
{
var ver = GetOsVersionByWmi();
_isTenOrNewer = (ver != null) && (10 <= ver.Major);
}

return _isTenOrNewer.Value;
}
}
private static bool? _isTenOrNewer;
private static readonly Lazy<bool> _isTenOrNewer = new Lazy<bool>(GetIsTenOrNewer);

private static bool GetIsTenOrNewer()
{
return (Ver != null) && (10 <= Ver.Major);
}

#region Helper

/// <summary>
/// OS version.
/// </summary>
private static Version Ver
{
get
{
return _ver.Value;
}
}
private static readonly Lazy<Version> _ver = new Lazy<Version>(GetOsVersionByWmi);

/// <summary>
/// Get OS version.
/// </summary>
Expand Down