Skip to content

Commit

Permalink
refactor: C# 12
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed Nov 18, 2023
1 parent cc40238 commit a05ae04
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/PipManager/Helpers/ActionExceptionAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PipManager.Helpers;

public static class ActionExceptionAnalyzer
{
public static string Analyze(this ActionListItem action)
public static string Analyze(this ActionListItem? action)
{
if (!action.DetectIssue) return "";
var speculations = "";
Expand Down
6 changes: 3 additions & 3 deletions src/PipManager/Models/Action/ActionListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public ActionListItem(ActionType operationType, string operationCommand, string
public bool ProgressIntermediate { get; set; }
public int TotalSubTaskNumber { get; set; }

private int completedSubTaskNumber;
private int _completedSubTaskNumber;

public int CompletedSubTaskNumber
{
get => completedSubTaskNumber;
get => _completedSubTaskNumber;
set
{
completedSubTaskNumber = value;
_completedSubTaskNumber = value;
ProgressBarValue = (double)value / TotalSubTaskNumber * 100.0;
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/PipManager/Models/Package/PackageItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace PipManager.Models.Package;

public class PackageItem
{
public string Name { get; set; }
public string Version { get; set; }
public PackageVersion DetailedVersion { get; set; }
public string Path { get; set; }
public string DistInfoPath { get; set; }
public string Summary { get; set; }
public List<string> Author { get; set; }
public string AuthorEmail { get; set; }
public List<LibraryDetailProjectUrlModel> ProjectUrl { get; set; }
public Dictionary<string, List<string>> Classifier { get; set; }
public Dictionary<string, List<string>> Metadata { get; set; }
public List<string> Record { get; set; }
public string? Name { get; set; }
public string? Version { get; set; }
public PackageVersion? DetailedVersion { get; set; }
public string? Path { get; set; }
public string? DistInfoPath { get; set; }
public string? Summary { get; set; }
public List<string>? Author { get; set; }
public string? AuthorEmail { get; set; }
public List<LibraryDetailProjectUrlModel>? ProjectUrl { get; set; }
public Dictionary<string, List<string>>? Classifier { get; set; }
public Dictionary<string, List<string>>? Metadata { get; set; }
public List<string>? Record { get; set; }
}
6 changes: 3 additions & 3 deletions src/PipManager/Models/Pages/LibraryDetailProjectUrlModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace PipManager.Models.Pages;

public class LibraryDetailProjectUrlModel
{
public SymbolIcon Icon { get; set; }
public string UrlType { get; set; }
public string Url { get; set; }
public SymbolIcon? Icon { get; set; }
public string? UrlType { get; set; }
public string? Url { get; set; }
}
14 changes: 7 additions & 7 deletions src/PipManager/Models/Pypi/PypiPackageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ namespace PipManager.Models.Pypi;
public class PypiPackageInfo
{
[JsonProperty("releases")]
public Dictionary<string, List<PypiPackageRelease>> Releases;
public required Dictionary<string, List<PypiPackageRelease>> Releases;
}

public class PypiPackageRelease
{
[JsonProperty("filename")]
public string Filename;
public required string Filename;

[JsonProperty("upload_time")]
public string UploadTime;
public required string UploadTime;

[JsonProperty("digests")]
public PypiPackageDigest Digests;
public required PypiPackageDigest Digests;
}

public class PypiPackageDigest
{
[JsonProperty("blake2b_256")]
public string Blake2B256;
public required string Blake2B256;

[JsonProperty("md5")]
public string Md5;
public required string Md5;

[JsonProperty("sha256")]
public string Sha256;
public required string Sha256;
}
12 changes: 3 additions & 9 deletions src/PipManager/ViewModels/Pages/About/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

namespace PipManager.ViewModels.Pages.About;

public partial class AboutViewModel : ObservableObject, INavigationAware
public partial class AboutViewModel(IConfigurationService configurationService) : ObservableObject, INavigationAware
{
private bool _isInitialized;
private readonly IConfigurationService _configurationService;

[ObservableProperty] private string _appVersion = "Development";
[ObservableProperty] private bool _debugMode;
[ObservableProperty] private bool _experimentMode;

public AboutViewModel(IConfigurationService configurationService)
{
_configurationService = configurationService;
}

public void OnNavigatedTo()
{
if (!_isInitialized)
Expand All @@ -32,8 +26,8 @@ public void OnNavigatedFrom()

private void InitializeViewModel()
{
DebugMode = _configurationService.DebugMode;
ExperimentMode = _configurationService.ExperimentMode;
DebugMode = configurationService.DebugMode;
ExperimentMode = configurationService.ExperimentMode;
AppVersion = AppInfo.AppVersion;
_isInitialized = true;
Log.Information("[About] Initialized");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void UpdateActionExceptionList()
}

[RelayCommand]
private void ShowException(object parameter)
private static void ShowException(object parameter)
{
var actionExceptionWindow = App.GetService<ActionExceptionWindow>();
actionExceptionWindow.Initialize(parameter as ActionListItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ActionExceptionWindow()
InitializeComponent();
}

public void Initialize(ActionListItem action)
public void Initialize(ActionListItem? action)
{
SpeculationTextBox.Text = action.Analyze();
OriginalExceptionTextBox.Text = Lang.ActionExceptionWindow_OriginalException + "\n" + action.ConsoleError;
Expand Down

0 comments on commit a05ae04

Please sign in to comment.