Skip to content

Commit f32bf44

Browse files
authored
Change OnPropertyChangeStrings to use nameof (#1374)
**Bug** Most of our calls to `OnPropertyChange` currently use string values. This is problematic because strings are not strongly typed, so they can easily get out of sync with the actual property names. **Fix** Change these calls to use `nameof` instead. This ensures that an error is produced if the names ever get out of sync. Also this makes c# refactorings do the correct thing.
1 parent 2e792d0 commit f32bf44

6 files changed

Lines changed: 25 additions & 28 deletions

File tree

Nodejs/Product/Nodejs/NpmUI/LastRefreshedMessageProvider.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,5 @@ public LastRefreshedMessageProvider(DateTime lastRefreshTime) {
6565
public int Days { get; private set; }
6666

6767
public string Description { get; private set; }
68-
69-
public bool IsOld { get { return Days > 7; } }
70-
public bool IsAncient { get { return Days > 14; } }
7168
}
7269
}

Nodejs/Product/Nodejs/NpmUI/NpmOutputViewModel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public bool IsExecutingCommand {
9999
Pulse();
100100
}
101101
OnPropertyChanged();
102-
OnPropertyChanged("ExecutionProgressVisibility");
103-
OnPropertyChanged("ExecutionIdleVisibility");
104-
OnPropertyChanged("IsCancellable");
102+
OnPropertyChanged(nameof(ExecutionProgressVisibility));
103+
OnPropertyChanged(nameof(ExecutionIdleVisibility));
104+
OnPropertyChanged(nameof(IsCancellable));
105105
}
106106
}
107107

@@ -148,7 +148,7 @@ public void Cancel() {
148148
}
149149

150150
UpdateStatusMessage();
151-
OnPropertyChanged("IsCancellable");
151+
OnPropertyChanged(nameof(IsCancellable));
152152
}
153153

154154
private void QueueCommand(QueuedNpmCommandInfo info) {
@@ -162,7 +162,7 @@ private void QueueCommand(QueuedNpmCommandInfo info) {
162162
}
163163

164164
UpdateStatusMessageSafe();
165-
OnPropertyChanged("IsCancellable");
165+
OnPropertyChanged(nameof(IsCancellable));
166166
}
167167

168168
public void QueueCommand(string arguments) {
@@ -217,7 +217,7 @@ await cmdr.InstallPackageByVersionAsync(
217217

218218
private void HandleCompletionSafe() {
219219
UpdateStatusMessage();
220-
OnPropertyChanged("IsCancellable");
220+
OnPropertyChanged(nameof(IsCancellable));
221221
}
222222

223223
private void commander_CommandCompleted(object sender, NpmCommandCompletedEventArgs e) {

Nodejs/Product/Nodejs/NpmUI/NpmPackageInstallViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public bool IsLoadingCatalog {
118118
private set {
119119
_isLoadingCatalog = value;
120120
OnPropertyChanged();
121-
OnPropertyChanged("CanRefreshCatalog");
121+
OnPropertyChanged(nameof(CanRefreshCatalog));
122122
}
123123
}
124124

@@ -155,7 +155,7 @@ public Visibility LoadingCatalogControlVisibility {
155155
set {
156156
_loadingCatalogControlVisibility = value;
157157
OnPropertyChanged();
158-
OnPropertyChanged("FilterControlsVisibility");
158+
OnPropertyChanged(nameof(FilterControlsVisibility));
159159
}
160160
}
161161

@@ -258,7 +258,7 @@ private bool IsFiltering {
258258
set {
259259
_isFiltering = value;
260260
OnPropertyChanged();
261-
OnPropertyChanged("PackageFilterState");
261+
OnPropertyChanged(nameof(PackageFilterState));
262262
}
263263
}
264264

@@ -276,7 +276,7 @@ public IList<PackageCatalogEntryViewModel> FilteredPackages {
276276
// PackageFilterState should be triggered before FilteredPackages
277277
// to allow the UI to update the status before the package list,
278278
// making for a smoother experience.
279-
OnPropertyChanged("PackageFilterState");
279+
OnPropertyChanged(nameof(PackageFilterState));
280280
OnPropertyChanged();
281281
}
282282
}
@@ -290,7 +290,7 @@ public string FilterText {
290290
IsFiltering = !string.IsNullOrWhiteSpace(_filterText);
291291

292292
OnPropertyChanged();
293-
OnPropertyChanged("PackageFilterState");
293+
OnPropertyChanged(nameof(PackageFilterState));
294294
}
295295
}
296296

Nodejs/Product/Profiling/Profiling/CompareReportsView.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public string BaselineFile {
8080
set {
8181
if (_baselineFile != value) {
8282
_baselineFile = value;
83-
OnPropertyChanged("BaselineFile");
83+
OnPropertyChanged(nameof(BaselineFile));
8484
}
8585
}
8686
}
@@ -95,7 +95,7 @@ public string ComparisonFile {
9595
set {
9696
if (_comparisonFile != value) {
9797
_comparisonFile = value;
98-
OnPropertyChanged("ComparisonFile");
98+
OnPropertyChanged(nameof(ComparisonFile));
9999
}
100100
}
101101
}
@@ -119,7 +119,7 @@ public bool IsValid {
119119
private set {
120120
if (_isValid != value) {
121121
_isValid = value;
122-
OnPropertyChanged("IsValid");
122+
OnPropertyChanged(nameof(IsValid));
123123
}
124124
}
125125
}

Nodejs/Product/Profiling/Profiling/ProfilingTargetView.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public ProjectTargetView Project {
127127
set {
128128
if (_project != value) {
129129
_project = value;
130-
OnPropertyChanged("Project");
130+
OnPropertyChanged(nameof(Project));
131131
}
132132
}
133133
}
@@ -142,7 +142,7 @@ public bool IsProjectSelected {
142142
set {
143143
if (_isProjectSelected != value) {
144144
_isProjectSelected = value;
145-
OnPropertyChanged("IsProjectSelected");
145+
OnPropertyChanged(nameof(IsProjectSelected));
146146
}
147147
}
148148
}
@@ -164,7 +164,7 @@ public StandaloneTargetView Standalone {
164164
_standalone.PropertyChanged += Standalone_PropertyChanged;
165165
}
166166

167-
OnPropertyChanged("Standalone");
167+
OnPropertyChanged(nameof(Standalone));
168168
}
169169
}
170170
}
@@ -179,7 +179,7 @@ public bool IsStandaloneSelected {
179179
set {
180180
if (_isStandaloneSelected != value) {
181181
_isStandaloneSelected = value;
182-
OnPropertyChanged("IsStandaloneSelected");
182+
OnPropertyChanged(nameof(IsStandaloneSelected));
183183
}
184184
}
185185
}
@@ -204,7 +204,7 @@ void ProfilingTargetView_PropertyChanged(object sender, PropertyChangedEventArgs
204204
/// </summary>
205205
private void Standalone_PropertyChanged(object sender, PropertyChangedEventArgs e) {
206206
Debug.Assert(Standalone == sender);
207-
OnPropertyChanged("Standalone");
207+
OnPropertyChanged(nameof(Standalone));
208208
}
209209

210210

@@ -218,7 +218,7 @@ public bool IsValid {
218218
private set {
219219
if (_isValid != value) {
220220
_isValid = value;
221-
OnPropertyChanged("IsValid");
221+
OnPropertyChanged(nameof(IsValid));
222222
}
223223
}
224224
}

Nodejs/Product/Profiling/Profiling/StandaloneTargetView.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public string InterpreterPath {
8585
set {
8686
if (_interpreterPath != value) {
8787
_interpreterPath = value;
88-
OnPropertyChanged("InterpreterPath");
88+
OnPropertyChanged(nameof(InterpreterPath));
8989
}
9090
}
9191
}
@@ -100,7 +100,7 @@ public string ScriptPath {
100100
set {
101101
if (_scriptPath != value) {
102102
_scriptPath = value;
103-
OnPropertyChanged("ScriptPath");
103+
OnPropertyChanged(nameof(ScriptPath));
104104
//if (string.IsNullOrEmpty(WorkingDirectory)) {
105105
// WorkingDirectory = Path.GetDirectoryName(_scriptPath);
106106
//}
@@ -118,7 +118,7 @@ public string WorkingDirectory {
118118
set {
119119
if (_workingDirectory != value) {
120120
_workingDirectory = value;
121-
OnPropertyChanged("WorkingDirectory");
121+
OnPropertyChanged(nameof(WorkingDirectory));
122122
}
123123
}
124124
}
@@ -133,7 +133,7 @@ public string Arguments {
133133
set {
134134
if (_arguments != value) {
135135
_arguments = value;
136-
OnPropertyChanged("Arguments");
136+
OnPropertyChanged(nameof(Arguments));
137137
}
138138
}
139139
}
@@ -164,7 +164,7 @@ public bool IsValid {
164164
private set {
165165
if (_isValid != value) {
166166
_isValid = value;
167-
OnPropertyChanged("IsValid");
167+
OnPropertyChanged(nameof(IsValid));
168168
}
169169
}
170170
}

0 commit comments

Comments
 (0)