diff --git a/.github/workflows/GitHubExt-CI.yml b/.github/workflows/GitHubExt-CI.yml
index a4420bf6..2c4b2c42 100644
--- a/.github/workflows/GitHubExt-CI.yml
+++ b/.github/workflows/GitHubExt-CI.yml
@@ -15,7 +15,7 @@ jobs:
configuration: [Release, Debug]
platform: [x64, x86, arm64]
os: [windows-latest]
- dotnet-version: ['6.0.x']
+ dotnet-version: ['8.0.x']
exclude:
- configuration: Debug
platform: x64
diff --git a/Directory.Build.props b/Directory.Build.props
index e293c534..7c2dc3c1 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -45,4 +45,15 @@
+
+
+
+
+ true
+
+
+
+
\ No newline at end of file
diff --git a/ToolingVersions.props b/ToolingVersions.props
index b6c8d340..f4a87568 100644
--- a/ToolingVersions.props
+++ b/ToolingVersions.props
@@ -2,7 +2,7 @@
- net6.0-windows10.0.22000.0
+ net8.0-windows10.0.22000.0
10.0.19041.0
10.0.19041.0
diff --git a/src/GitHubExtension/Client/Validation.cs b/src/GitHubExtension/Client/Validation.cs
index d731b911..b83d4904 100644
--- a/src/GitHubExtension/Client/Validation.cs
+++ b/src/GitHubExtension/Client/Validation.cs
@@ -214,7 +214,7 @@ private static string AddProtocolToString(string s)
private static string[]? GetNameAndRepoFromFullName(string s)
{
- var n = s.Split(new[] { '/' });
+ var n = s.Split(['/']);
// This should be exactly two results with no empty strings.
if (n.Length != 2 || string.IsNullOrEmpty(n[0]) || string.IsNullOrEmpty(n[1]))
diff --git a/src/GitHubExtension/Constants.cs b/src/GitHubExtension/Constants.cs
index 3728442f..579cb7c3 100644
--- a/src/GitHubExtension/Constants.cs
+++ b/src/GitHubExtension/Constants.cs
@@ -3,7 +3,7 @@
namespace GitHubExtension;
-internal class Constants
+internal sealed class Constants
{
#pragma warning disable SA1310 // Field names should not contain underscore
public const string DEV_HOME_APPLICATION_NAME = "DevHome";
diff --git a/src/GitHubExtension/DataManager/GitHubDataManager.cs b/src/GitHubExtension/DataManager/GitHubDataManager.cs
index 68837289..d7c10a7e 100644
--- a/src/GitHubExtension/DataManager/GitHubDataManager.cs
+++ b/src/GitHubExtension/DataManager/GitHubDataManager.cs
@@ -104,7 +104,7 @@ await UpdateDataForRepositoryAsync(
await UpdatePullRequestsAsync(repository, devId.GitHubClient, parameters.RequestOptions);
});
- SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "Issues", "PullRequests" });
+ SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), _IssuesAndPRs);
}
public async Task UpdateAllDataForRepositoryAsync(string fullName, RequestOptions? options = null)
@@ -133,7 +133,7 @@ await UpdateDataForRepositoryAsync(
await UpdatePullRequestsAsync(repository, devId.GitHubClient, parameters.RequestOptions);
});
- SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "PullRequests" });
+ SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), _PRs);
}
public async Task UpdatePullRequestsForRepositoryAsync(string fullName, RequestOptions? options = null)
@@ -162,7 +162,7 @@ await UpdateDataForRepositoryAsync(
await UpdateIssuesAsync(repository, devId.GitHubClient, parameters.RequestOptions);
});
- SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "Issues" });
+ SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), _Issues);
}
public async Task UpdateIssuesForRepositoryAsync(string fullName, RequestOptions? options = null)
@@ -202,7 +202,7 @@ await UpdateDataForRepositoryAsync(
await UpdateReleasesAsync(repository, devId.GitHubClient, parameters.RequestOptions);
});
- SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), new string[] { "Releases" });
+ SendRepositoryUpdateEvent(this, GetFullNameFromOwnerAndRepository(owner, name), _Releases);
}
public IEnumerable GetRepositories()
@@ -788,7 +788,7 @@ private void SetLastUpdatedInMetaData()
// Converts fullName -> owner, name.
private string[] GetOwnerAndRepositoryNameFromFullName(string fullName)
{
- var nameSplit = fullName.Split(new[] { '/' });
+ var nameSplit = fullName.Split(['/']);
if (nameSplit.Length != 2 || string.IsNullOrEmpty(nameSplit[0]) || string.IsNullOrEmpty(nameSplit[1]))
{
Log.Error($"Invalid repository full name: {fullName}");
@@ -842,6 +842,10 @@ private static DataStoreOptions DefaultOptionsInit()
public override string ToString() => "GitHubDataManager";
private bool disposed; // To detect redundant calls.
+ private static readonly string[] _IssuesAndPRs = new string[] { "Issues", "PullRequests" };
+ private static readonly string[] _PRs = new string[] { "PullRequests" };
+ private static readonly string[] _Issues = new string[] { "Issues" };
+ private static readonly string[] _Releases = new string[] { "Releases" };
protected virtual void Dispose(bool disposing)
{
diff --git a/src/GitHubExtension/DataModel/DataObjects/Repository.cs b/src/GitHubExtension/DataModel/DataObjects/Repository.cs
index a48aff35..954a8976 100644
--- a/src/GitHubExtension/DataModel/DataObjects/Repository.cs
+++ b/src/GitHubExtension/DataModel/DataObjects/Repository.cs
@@ -274,7 +274,7 @@ public static IEnumerable GetAll(DataStore dataStore)
public static Repository? Get(DataStore dataStore, string fullName)
{
- var nameSplit = fullName.Split(new[] { '/' }, 2);
+ var nameSplit = fullName.Split(['/'], 2);
if (nameSplit.Length != 2)
{
Log.Warning($"Invalid fullName input into Repository.Get: {fullName}");
diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs
index 51234cc6..8a3cb35d 100644
--- a/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs
+++ b/src/GitHubExtension/DeveloperId/LoginUI/EndPage.cs
@@ -3,7 +3,7 @@
namespace GitHubExtension.DeveloperId.LoginUI;
-internal class EndPage : LoginUIPage
+internal sealed class EndPage : LoginUIPage
{
public EndPage()
: base(LoginUIState.End)
diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs
index b94740b5..608a0a94 100644
--- a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs
+++ b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPATPage.cs
@@ -6,7 +6,7 @@
namespace GitHubExtension.DeveloperId.LoginUI;
-internal class EnterpriseServerPATPage : LoginUIPage
+internal sealed class EnterpriseServerPATPage : LoginUIPage
{
public EnterpriseServerPATPage(Uri hostAddress, string errorText, SecureString inputPAT)
: base(LoginUIState.EnterpriseServerPATPage)
@@ -21,7 +21,7 @@ public EnterpriseServerPATPage(Uri hostAddress, string errorText, SecureString i
};
}
- internal class PageData : ILoginUIPageData
+ internal sealed class PageData : ILoginUIPageData
{
public string EnterpriseServerPATPageInputValue { get; set; } = string.Empty;
@@ -39,7 +39,7 @@ public string GetJson()
}
}
- internal class ActionPayload : SubmitActionPayload
+ internal sealed class ActionPayload : SubmitActionPayload
{
public string? URL
{
@@ -47,7 +47,7 @@ public string? URL
}
}
- internal class InputPayload
+ internal sealed class InputPayload
{
public string? PAT
{
diff --git a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs
index bc6842b2..b5e09908 100644
--- a/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs
+++ b/src/GitHubExtension/DeveloperId/LoginUI/EnterpriseServerPage.cs
@@ -5,7 +5,7 @@
namespace GitHubExtension.DeveloperId.LoginUI;
-internal class EnterpriseServerPage : LoginUIPage
+internal sealed class EnterpriseServerPage : LoginUIPage
{
public EnterpriseServerPage(Uri? hostAddress, string errorText)
: base(LoginUIState.EnterpriseServerPage)
@@ -29,7 +29,7 @@ public EnterpriseServerPage(string hostAddress, string errorText)
};
}
- internal class PageData : ILoginUIPageData
+ internal sealed class PageData : ILoginUIPageData
{
public string EnterpriseServerInputValue { get; set; } = string.Empty;
@@ -44,11 +44,11 @@ public string GetJson()
}
}
- internal class ActionPayload : SubmitActionPayload
+ internal sealed class ActionPayload : SubmitActionPayload
{
}
- internal class InputPayload
+ internal sealed class InputPayload
{
public string? EnterpriseServer
{
diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs
index a8144102..cda9985b 100644
--- a/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs
+++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginFailedPage.cs
@@ -5,7 +5,7 @@
namespace GitHubExtension.DeveloperId.LoginUI;
-internal class LoginFailedPage : LoginUIPage
+internal sealed class LoginFailedPage : LoginUIPage
{
public LoginFailedPage()
: base(LoginUIState.LoginFailedPage)
@@ -13,7 +13,7 @@ public LoginFailedPage()
Data = new LoginFailedPageData();
}
- internal class LoginFailedPageData : ILoginUIPageData
+ internal sealed class LoginFailedPageData : ILoginUIPageData
{
public string GetJson()
{
diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs
index 688ec225..53b542a0 100644
--- a/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs
+++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginPage.cs
@@ -5,7 +5,7 @@
namespace GitHubExtension.DeveloperId.LoginUI;
-internal class LoginPage : LoginUIPage
+internal sealed class LoginPage : LoginUIPage
{
public LoginPage()
: base(LoginUIState.LoginPage)
@@ -13,7 +13,7 @@ public LoginPage()
Data = new PageData();
}
- internal class PageData : ILoginUIPageData
+ internal sealed class PageData : ILoginUIPageData
{
public string GetJson()
{
@@ -21,7 +21,7 @@ public string GetJson()
}
}
- internal class ActionPayload : SubmitActionPayload
+ internal sealed class ActionPayload : SubmitActionPayload
{
public bool IsEnterprise()
{
diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs
index 5ef03649..511c1789 100644
--- a/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs
+++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginSucceededPage.cs
@@ -6,7 +6,7 @@
namespace GitHubExtension.DeveloperId.LoginUI;
-internal class LoginSucceededPage : LoginUIPage
+internal sealed class LoginSucceededPage : LoginUIPage
{
public LoginSucceededPage(IDeveloperId developerId)
: base(LoginUIState.LoginSucceededPage)
@@ -17,7 +17,7 @@ public LoginSucceededPage(IDeveloperId developerId)
};
}
- internal class LoginSucceededPageData : ILoginUIPageData
+ internal sealed class LoginSucceededPageData : ILoginUIPageData
{
public string? Message { get; set; } = string.Empty;
diff --git a/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs
index d6fe7453..063cee7d 100644
--- a/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs
+++ b/src/GitHubExtension/DeveloperId/LoginUI/LoginUIPage.cs
@@ -31,10 +31,7 @@ public LoginUIPage(LoginUIState state)
public ProviderOperationResult UpdateExtensionAdaptiveCard(IExtensionAdaptiveCard adaptiveCard)
{
- if (adaptiveCard == null)
- {
- throw new ArgumentNullException(nameof(adaptiveCard));
- }
+ ArgumentNullException.ThrowIfNull(adaptiveCard);
return adaptiveCard.Update(_template, _data?.GetJson(), Enum.GetName(typeof(LoginUIState), _state));
}
diff --git a/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs b/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs
index 19739c8b..d03a5925 100644
--- a/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs
+++ b/src/GitHubExtension/DeveloperId/LoginUI/WaitingPage.cs
@@ -5,7 +5,7 @@
namespace GitHubExtension.DeveloperId.LoginUI;
-internal class WaitingPage : LoginUIPage
+internal sealed class WaitingPage : LoginUIPage
{
public WaitingPage()
: base(LoginUIState.WaitingPage)
@@ -13,7 +13,7 @@ public WaitingPage()
Data = new WaitingPageData();
}
- internal class WaitingPageData : ILoginUIPageData
+ internal sealed class WaitingPageData : ILoginUIPageData
{
public string GetJson()
{
diff --git a/src/GitHubExtension/DeveloperId/OAuthRequest.cs b/src/GitHubExtension/DeveloperId/OAuthRequest.cs
index 5b685ab4..3ab42422 100644
--- a/src/GitHubExtension/DeveloperId/OAuthRequest.cs
+++ b/src/GitHubExtension/DeveloperId/OAuthRequest.cs
@@ -11,7 +11,7 @@
namespace GitHubExtension.DeveloperId;
-internal class OAuthRequest : IDisposable
+internal sealed class OAuthRequest : IDisposable
{
private static readonly Lazy _log = new(() => Serilog.Log.ForContext("SourceContext", nameof(OAuthRequest)));
@@ -33,7 +33,7 @@ internal OAuthRequest()
State = string.Empty;
}
- protected virtual void Dispose(bool disposing)
+ private void Dispose(bool disposing)
{
if (disposing)
{
diff --git a/src/GitHubExtension/Helpers/IconLoader.cs b/src/GitHubExtension/Helpers/IconLoader.cs
index bd113a74..a6cdb7a6 100644
--- a/src/GitHubExtension/Helpers/IconLoader.cs
+++ b/src/GitHubExtension/Helpers/IconLoader.cs
@@ -13,9 +13,8 @@ public static string GetIconAsBase64(string filename)
{
var log = Log.ForContext("SourceContext", nameof(IconLoader));
log.Verbose($"Asking for icon: {filename}");
- if (!Base64ImageRegistry.ContainsKey(filename))
+ if (!Base64ImageRegistry.TryAdd(filename, ConvertIconToDataString(filename)))
{
- Base64ImageRegistry.Add(filename, ConvertIconToDataString(filename));
log.Verbose($"The icon {filename} was converted and is now stored.");
}
diff --git a/src/GitHubExtension/Helpers/Json.cs b/src/GitHubExtension/Helpers/Json.cs
index 314d3a9a..93be1d14 100644
--- a/src/GitHubExtension/Helpers/Json.cs
+++ b/src/GitHubExtension/Helpers/Json.cs
@@ -9,6 +9,13 @@ namespace GitHubExtension.Helpers;
public static class Json
{
+ private static readonly JsonSerializerOptions Options = new()
+ {
+ PropertyNameCaseInsensitive = true,
+ DefaultIgnoreCondition = JsonIgnoreCondition.Never,
+ IncludeFields = true,
+ };
+
public static async Task ToObjectAsync(string value)
{
if (typeof(T) == typeof(bool))
@@ -42,14 +49,7 @@ public static string Stringify(T value)
return value!.ToString()!.ToLowerInvariant();
}
- return System.Text.Json.JsonSerializer.Serialize(
- value,
- new JsonSerializerOptions
- {
- PropertyNameCaseInsensitive = true,
- DefaultIgnoreCondition = JsonIgnoreCondition.Never,
- IncludeFields = true,
- });
+ return System.Text.Json.JsonSerializer.Serialize(value, Options);
}
public static T? ToObject(string json)
@@ -59,11 +59,6 @@ public static string Stringify(T value)
return (T)(object)bool.Parse(json);
}
- return System.Text.Json.JsonSerializer.Deserialize(json, new JsonSerializerOptions
- {
- PropertyNameCaseInsensitive = true,
- DefaultIgnoreCondition = JsonIgnoreCondition.Never,
- IncludeFields = true,
- });
+ return System.Text.Json.JsonSerializer.Deserialize(json, Options);
}
}
diff --git a/src/GitHubExtension/Helpers/LocalSettings.cs b/src/GitHubExtension/Helpers/LocalSettings.cs
index 76563412..542f0252 100644
--- a/src/GitHubExtension/Helpers/LocalSettings.cs
+++ b/src/GitHubExtension/Helpers/LocalSettings.cs
@@ -11,7 +11,7 @@ public static class LocalSettings
private static readonly string _applicationDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DevHome/ApplicationData");
private static readonly string _localSettingsFile = "LocalSettings.json";
- private static IDictionary? _settings;
+ private static Dictionary? _settings;
private static async Task InitializeAsync()
{
@@ -23,7 +23,7 @@ private static async Task InitializeAsync()
}
else
{
- _settings = await Task.Run(() => FileHelper.Read>(_applicationDataFolder, _localSettingsFile)) ?? new Dictionary();
+ _settings = await Task.Run(() => FileHelper.Read>(_applicationDataFolder, _localSettingsFile)) ?? new Dictionary();
}
}
}
diff --git a/src/GitHubExtension/Helpers/TimeSpanHelper.cs b/src/GitHubExtension/Helpers/TimeSpanHelper.cs
index 2bd628be..4498ef30 100644
--- a/src/GitHubExtension/Helpers/TimeSpanHelper.cs
+++ b/src/GitHubExtension/Helpers/TimeSpanHelper.cs
@@ -6,7 +6,7 @@
namespace GitHubExtension.Helpers;
-internal class TimeSpanHelper
+internal sealed class TimeSpanHelper
{
public static string TimeSpanToDisplayString(TimeSpan timeSpan, ILogger? log = null)
{
diff --git a/src/GitHubExtension/Notifications/NotificationHandler.cs b/src/GitHubExtension/Notifications/NotificationHandler.cs
index e6795200..b54e509a 100644
--- a/src/GitHubExtension/Notifications/NotificationHandler.cs
+++ b/src/GitHubExtension/Notifications/NotificationHandler.cs
@@ -24,13 +24,13 @@ public static void NotificationActivation(AppNotificationActivatedEventArgs args
{
Log.Information($"Notification Activated with args: {NotificationArgsToString(args)}");
- if (args.Arguments.ContainsKey("htmlurl"))
+ if (args.Arguments.TryGetValue("htmlurl", out var htmlUrl))
{
try
{
// Do not assume this string is a safe URL and blindly execute it; verify that it is
// in fact a valid GitHub URL.
- var urlString = args.Arguments["htmlurl"];
+ var urlString = htmlUrl;
if (!Validation.IsValidGitHubURL(urlString))
{
throw new InvalidGitHubUrlException($"{urlString} is invalid.");
@@ -47,7 +47,7 @@ public static void NotificationActivation(AppNotificationActivatedEventArgs args
}
catch (Exception ex)
{
- Log.Error(ex, $"Failed launching Uri for {args.Arguments["htmlurl"]}");
+ Log.Error(ex, $"Failed launching Uri for {htmlUrl}");
}
return;
diff --git a/src/GitHubExtension/Providers/SettingsUIController.cs b/src/GitHubExtension/Providers/SettingsUIController.cs
index a697dad6..7c8a6f75 100644
--- a/src/GitHubExtension/Providers/SettingsUIController.cs
+++ b/src/GitHubExtension/Providers/SettingsUIController.cs
@@ -9,7 +9,7 @@
namespace GitHubExtension.Providers;
-internal class SettingsUIController : IExtensionAdaptiveCardSession
+internal sealed class SettingsUIController : IExtensionAdaptiveCardSession
{
private static readonly Lazy _log = new(() => Serilog.Log.ForContext("SourceContext", nameof(RepositoryProvider)));
@@ -68,7 +68,7 @@ public IAsyncOperation OnAction(string action, string i
}
// Adaptive Card Templates for SettingsUI.
- private class SettingsUITemplate
+ private sealed class SettingsUITemplate
{
internal string GetSettingsUITemplate()
{
diff --git a/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs b/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs
index 45ea2655..7d20b0fa 100644
--- a/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs
+++ b/src/GitHubExtension/Widgets/GitHubAssignedWidget.cs
@@ -5,7 +5,7 @@
namespace GitHubExtension.Widgets;
-internal class GitHubAssignedWidget : GitHubUserWidget
+internal sealed class GitHubAssignedWidget : GitHubUserWidget
{
private static readonly string TitleIconData =
"iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAAAlwS" +
@@ -55,8 +55,6 @@ internal class GitHubAssignedWidget : GitHubUserWidget
"qSu2i3mQQP0mcwBzBQei0stR7+mT+v5X9v6Wl8Aqo7k1lqZ/uoAbm/GE7ZbUpqgByOe57MDXG" +
"k5sHfmNwyTXv6g+Z9V32JXdGMYwhjGMYQzLYNOm/wESzvR5z0LQ4QAAAABJRU5ErkJggg==";
- protected static readonly new string Name = nameof(GitHubAssignedWidget);
-
protected override string GetTitleIconData()
{
return TitleIconData;
diff --git a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs
index 79ba19a2..d5da134c 100644
--- a/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs
+++ b/src/GitHubExtension/Widgets/GitHubIssuesWidget.cs
@@ -10,7 +10,7 @@
namespace GitHubExtension.Widgets;
-internal class GitHubIssuesWidget : GitHubRepositoryWidget
+internal sealed class GitHubIssuesWidget : GitHubRepositoryWidget
{
private readonly string issuesIconData = IconLoader.GetIconAsBase64("issues.png");
diff --git a/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs b/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs
index 93e55bf3..1a63b826 100644
--- a/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs
+++ b/src/GitHubExtension/Widgets/GitHubMentionedInWidget.cs
@@ -5,7 +5,7 @@
namespace GitHubExtension.Widgets;
-internal class GitHubMentionedInWidget : GitHubUserWidget
+internal sealed class GitHubMentionedInWidget : GitHubUserWidget
{
private static readonly string TitleIconData =
"iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAAA" +
diff --git a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs
index f373ba30..00459225 100644
--- a/src/GitHubExtension/Widgets/GitHubPullsWidget.cs
+++ b/src/GitHubExtension/Widgets/GitHubPullsWidget.cs
@@ -10,7 +10,7 @@
namespace GitHubExtension.Widgets;
-internal class GitHubPullsWidget : GitHubRepositoryWidget
+internal sealed class GitHubPullsWidget : GitHubRepositoryWidget
{
private readonly string pullsIconData = IconLoader.GetIconAsBase64("pulls.png");
diff --git a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs
index 80c1e527..8e346d84 100644
--- a/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs
+++ b/src/GitHubExtension/Widgets/GitHubReleasesWidget.cs
@@ -10,7 +10,7 @@
namespace GitHubExtension.Widgets;
-internal class GitHubReleasesWidget : GitHubRepositoryWidget
+internal sealed class GitHubReleasesWidget : GitHubRepositoryWidget
{
private readonly string _releasesIconData = IconLoader.GetIconAsBase64("releases.png");
@@ -122,7 +122,7 @@ public override void LoadContentData()
releasesData.Add("releases", releasesArray);
releasesData.Add("selected_repo", repository?.FullName ?? string.Empty);
- releasesData.Add("widgetTitle", WidgetTitle);
+ releasesData.Add("widgetTitle", WidgetTitle);
releasesData.Add("is_loading_data", DataState == WidgetDataState.Unknown);
releasesData.Add("releases_icon_data", _releasesIconData);
diff --git a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs
index ac7f0e7a..c4b6e872 100644
--- a/src/GitHubExtension/Widgets/GitHubReviewWidget.cs
+++ b/src/GitHubExtension/Widgets/GitHubReviewWidget.cs
@@ -9,7 +9,7 @@
namespace GitHubExtension.Widgets;
-internal class GitHubReviewWidget : GitHubUserWidget
+internal sealed class GitHubReviewWidget : GitHubUserWidget
{
public GitHubReviewWidget()
: base()
diff --git a/src/GitHubExtension/Widgets/GitHubWidget.cs b/src/GitHubExtension/Widgets/GitHubWidget.cs
index 98d06f75..85059d29 100644
--- a/src/GitHubExtension/Widgets/GitHubWidget.cs
+++ b/src/GitHubExtension/Widgets/GitHubWidget.cs
@@ -79,7 +79,7 @@ public override void CreateWidget(WidgetContext widgetContext, string state)
// If there is a state, it is being retrieved from the widget service, so
// this widget was pinned before.
- if (state.Any())
+ if (state.Length != 0)
{
ResetWidgetInfoFromState();
Saved = true;
@@ -205,7 +205,7 @@ public string GetSignIn()
public bool IsUserLoggedIn()
{
- IDeveloperIdProvider authProvider = DeveloperIdProvider.GetInstance();
+ DeveloperIdProvider authProvider = DeveloperIdProvider.GetInstance();
return authProvider.GetLoggedInDeveloperIds().DeveloperIds.Any();
}
@@ -259,10 +259,10 @@ public virtual string GetData(WidgetPageState page)
protected string GetTemplateForPage(WidgetPageState page)
{
- if (Template.ContainsKey(page))
+ if (Template.TryGetValue(page, out var pageTemplate))
{
Log.Debug($"Using cached template for {page}");
- return Template[page];
+ return pageTemplate;
}
try
diff --git a/src/GitHubExtension/Widgets/WidgetImplFactory.cs b/src/GitHubExtension/Widgets/WidgetImplFactory.cs
index 661ec1e5..602a4f2e 100644
--- a/src/GitHubExtension/Widgets/WidgetImplFactory.cs
+++ b/src/GitHubExtension/Widgets/WidgetImplFactory.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation.
+// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.Windows.Widgets.Providers;
@@ -7,7 +7,7 @@
namespace GitHubExtension.Widgets;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Templated class")]
-internal class WidgetImplFactory : IWidgetImplFactory
+internal sealed class WidgetImplFactory : IWidgetImplFactory
where T : WidgetImpl, new()
{
public WidgetImpl Create(WidgetContext widgetContext, string state)
diff --git a/src/GitHubExtension/Widgets/WidgetProvider.cs b/src/GitHubExtension/Widgets/WidgetProvider.cs
index f9f1181d..16d523d9 100644
--- a/src/GitHubExtension/Widgets/WidgetProvider.cs
+++ b/src/GitHubExtension/Widgets/WidgetProvider.cs
@@ -34,11 +34,11 @@ private void InitializeWidget(WidgetContext widgetContext, string state)
var widgetId = widgetContext.Id;
var widgetDefinitionId = widgetContext.DefinitionId;
_log.Verbose($"Calling Initialize for Widget Id: {widgetId} - {widgetDefinitionId}");
- if (widgetDefinitionRegistry.ContainsKey(widgetDefinitionId))
+ if (widgetDefinitionRegistry.TryGetValue(widgetDefinitionId, out var widgetDefinition))
{
if (!runningWidgets.ContainsKey(widgetId))
{
- var factory = widgetDefinitionRegistry[widgetDefinitionId];
+ var factory = widgetDefinition;
var widgetImpl = factory.Create(widgetContext, state);
runningWidgets.Add(widgetId, widgetImpl);
}
@@ -93,18 +93,18 @@ public void Activate(WidgetContext widgetContext)
{
_log.Verbose($"Activate id: {widgetContext.Id} definitionId: {widgetContext.DefinitionId}");
var widgetId = widgetContext.Id;
- if (runningWidgets.ContainsKey(widgetId))
+ if (runningWidgets.TryGetValue(widgetId, out var widget))
{
- runningWidgets[widgetId].Activate(widgetContext);
+ widget.Activate(widgetContext);
}
else
{
// Called to activate a widget that we don't know about, which is unexpected. Try to recover by creating it.
_log.Warning($"Found WidgetId that was not known: {widgetContext.Id}, attempting to recover by creating it.");
CreateWidget(widgetContext);
- if (runningWidgets.ContainsKey(widgetId))
+ if (runningWidgets.TryGetValue(widgetId, out var newWidget))
{
- runningWidgets[widgetId].Activate(widgetContext);
+ newWidget.Activate(widgetContext);
}
}
}
@@ -112,18 +112,18 @@ public void Activate(WidgetContext widgetContext)
public void Deactivate(string widgetId)
{
_log.Verbose($"Deactivate id: {widgetId}");
- if (runningWidgets.ContainsKey(widgetId))
+ if (runningWidgets.TryGetValue(widgetId, out var widget))
{
- runningWidgets[widgetId].Deactivate(widgetId);
+ widget.Deactivate(widgetId);
}
}
public void DeleteWidget(string widgetId, string customState)
{
_log.Information($"DeleteWidget id: {widgetId}");
- if (runningWidgets.ContainsKey(widgetId))
+ if (runningWidgets.TryGetValue(widgetId, out var widget))
{
- runningWidgets[widgetId].DeleteWidget(widgetId, customState);
+ widget.DeleteWidget(widgetId, customState);
runningWidgets.Remove(widgetId);
}
}
@@ -133,9 +133,9 @@ public void OnActionInvoked(WidgetActionInvokedArgs actionInvokedArgs)
_log.Debug($"OnActionInvoked id: {actionInvokedArgs.WidgetContext.Id} definitionId: {actionInvokedArgs.WidgetContext.DefinitionId}");
var widgetContext = actionInvokedArgs.WidgetContext;
var widgetId = widgetContext.Id;
- if (runningWidgets.ContainsKey(widgetId))
+ if (runningWidgets.TryGetValue(widgetId, out var widget))
{
- runningWidgets[widgetId].OnActionInvoked(actionInvokedArgs);
+ widget.OnActionInvoked(actionInvokedArgs);
}
}
@@ -144,9 +144,9 @@ public void OnCustomizationRequested(WidgetCustomizationRequestedArgs customizat
_log.Debug($"OnCustomizationRequested id: {customizationRequestedArgs.WidgetContext.Id} definitionId: {customizationRequestedArgs.WidgetContext.DefinitionId}");
var widgetContext = customizationRequestedArgs.WidgetContext;
var widgetId = widgetContext.Id;
- if (runningWidgets.ContainsKey(widgetId))
+ if (runningWidgets.TryGetValue(widgetId, out var widget))
{
- runningWidgets[widgetId].OnCustomizationRequested(customizationRequestedArgs);
+ widget.OnCustomizationRequested(customizationRequestedArgs);
}
}
@@ -155,9 +155,9 @@ public void OnWidgetContextChanged(WidgetContextChangedArgs contextChangedArgs)
_log.Debug($"OnWidgetContextChanged id: {contextChangedArgs.WidgetContext.Id} definitionId: {contextChangedArgs.WidgetContext.DefinitionId}");
var widgetContext = contextChangedArgs.WidgetContext;
var widgetId = widgetContext.Id;
- if (runningWidgets.ContainsKey(widgetId))
+ if (runningWidgets.TryGetValue(widgetId, out var widget))
{
- runningWidgets[widgetId].OnWidgetContextChanged(contextChangedArgs);
+ widget.OnWidgetContextChanged(contextChangedArgs);
}
}
}
diff --git a/src/GitHubExtension/Widgets/WidgetServer.cs b/src/GitHubExtension/Widgets/WidgetServer.cs
index d3a0128a..af4523b5 100644
--- a/src/GitHubExtension/Widgets/WidgetServer.cs
+++ b/src/GitHubExtension/Widgets/WidgetServer.cs
@@ -65,7 +65,7 @@ public void Dispose()
}
}
- private class Ole32
+ private sealed class Ole32
{
#pragma warning disable SA1310 // Field names should not contain underscore
// https://docs.microsoft.com/windows/win32/api/wtypesbase/ne-wtypesbase-clsctx
diff --git a/src/Telemetry/Logger.cs b/src/Telemetry/Logger.cs
index 4f8275f3..fd688937 100644
--- a/src/Telemetry/Logger.cs
+++ b/src/Telemetry/Logger.cs
@@ -12,7 +12,7 @@
namespace GitHubExtension.Telemetry;
-internal class Logger : ILogger
+internal sealed class Logger : ILogger
{
private const string ProviderName = "Microsoft.GitHubExtension";