Skip to content

Commit 3ebb1a8

Browse files
committed
Use 'field' keyword
1 parent eee14b3 commit 3ebb1a8

File tree

6 files changed

+28
-27
lines changed

6 files changed

+28
-27
lines changed

YouTube download tool.sln

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29209.152
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.35806.103
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YouTubeDownloadTool", "src\YouTubeDownloadTool\YouTubeDownloadTool.csproj", "{3F15C158-ADA8-4817-A109-23DC63E4D82A}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9DB62BA4-D4BC-42EB-9B45-C008DD51C4E3}"
99
ProjectSection(SolutionItems) = preProject
1010
.editorconfig = .editorconfig
11+
global.json = global.json
1112
EndProjectSection
1213
EndProject
1314
Global

global.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": {
3+
"version": "9.0.100",
4+
"rollForward": "latestMajor",
5+
"allowPrerelease": false
6+
}
7+
}

src/YouTubeDownloadTool/Command.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace YouTubeDownloadTool;
66
public sealed class Command : ICommand
77
{
88
private readonly Action action;
9-
private bool canExecute = true;
109

1110
public Command(Action action)
1211
{
@@ -20,18 +19,18 @@ public Command(Func<Task> asyncAction)
2019

2120
public bool CanExecute
2221
{
23-
get => canExecute;
22+
get;
2423
set
2524
{
26-
if (canExecute == value) return;
27-
canExecute = value;
25+
if (field == value) return;
26+
field = value;
2827
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
2928
}
30-
}
29+
} = true;
3130

3231
public event EventHandler? CanExecuteChanged;
3332

34-
bool ICommand.CanExecute(object? parameter) => canExecute;
33+
bool ICommand.CanExecute(object? parameter) => CanExecute;
3534

3635
void ICommand.Execute(object? parameter) => action.Invoke();
3736
}

src/YouTubeDownloadTool/MainViewModel.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,19 @@ public sealed class MainViewModel : ObservableObject
1111
private readonly IDownloadDataAccess dataAccess;
1212
private readonly Action<(string Message, bool IsError)> showNotification;
1313

14-
private string? downloadUrl;
15-
public string? DownloadUrl { get => downloadUrl; set => Set(ref downloadUrl, value); }
14+
public string? DownloadUrl { get; set => Set(ref field, value); }
1615

17-
private bool audioOnly;
18-
public bool AudioOnly { get => audioOnly; set => Set(ref audioOnly, value); }
16+
public bool AudioOnly { get; set => Set(ref field, value); }
1917

20-
private string? destinationFolder;
21-
public string? DestinationFolder { get => destinationFolder; set => Set(ref destinationFolder, value); }
18+
public string? DestinationFolder { get; set => Set(ref field, value); }
2219

23-
private double? progressFraction;
24-
public double? ProgressFraction { get => progressFraction; set => Set(ref progressFraction, value); }
20+
public double? ProgressFraction { get; set => Set(ref field, value); }
2521

26-
private bool isEditable = true;
27-
public bool IsEditable { get => isEditable; set => Set(ref isEditable, value); }
22+
public bool IsEditable { get; set => Set(ref field, value); } = true;
2823

29-
private bool isProgressBarVisible;
30-
public bool IsProgressBarVisible { get => isProgressBarVisible; set => Set(ref isProgressBarVisible, value); }
24+
public bool IsProgressBarVisible { get; set => Set(ref field, value); }
3125

32-
private string? status;
33-
public string? Status { get => status; set => Set(ref status, value); }
26+
public string? Status { get; set => Set(ref field, value); }
3427

3528
public Command Start { get; }
3629

@@ -41,9 +34,9 @@ public MainViewModel(IDownloadDataAccess dataAccess, Action<(string Message, boo
4134
this.dataAccess = dataAccess;
4235
this.showNotification = showNotification;
4336

44-
audioOnly = Properties.Settings.Default.AudioOnly;
37+
AudioOnly = Properties.Settings.Default.AudioOnly;
4538

46-
destinationFolder = Directory.Exists(Properties.Settings.Default.DestinationFolder)
39+
DestinationFolder = Directory.Exists(Properties.Settings.Default.DestinationFolder)
4740
? Properties.Settings.Default.DestinationFolder
4841
: Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
4942

src/YouTubeDownloadTool/ToolLease.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace YouTubeDownloadTool;
44

55
public sealed class ToolLease : IDisposable
66
{
7-
private readonly string filePath;
87
private IDisposable? lease;
98

109
public ToolLease(string version, string filePath, IDisposable lease)
@@ -16,15 +15,15 @@ public ToolLease(string version, string filePath, IDisposable lease)
1615
throw new ArgumentException("File path must be fully qualified.", nameof(filePath));
1716

1817
Version = version;
19-
this.filePath = filePath;
18+
FilePath = filePath;
2019
this.lease = lease ?? throw new ArgumentNullException(nameof(lease));
2120
}
2221

2322
public string Version { get; }
2423

2524
public string FilePath => Volatile.Read(ref lease) is null
2625
? throw new ObjectDisposedException(nameof(ToolLease))
27-
: filePath;
26+
: field;
2827

2928
public void Dispose()
3029
{

src/YouTubeDownloadTool/YouTubeDownloadTool.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<PublishSingleFile>true</PublishSingleFile>
1616
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
1717

18+
<LangVersion>preview</LangVersion>
19+
1820
<TreatWarningsAsErrors Condition="'$(Configuration)' != 'Debug'">true</TreatWarningsAsErrors>
1921
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
2022
</PropertyGroup>

0 commit comments

Comments
 (0)