[Code refactoring] Make code comment and NullOrEmpty check more clear (#13352)

* Clarify code

* grammar fix

* comment change
This commit is contained in:
Heiko 2021-09-22 23:43:28 +02:00 committed by GitHub
parent b05378cdf7
commit a0ebe5ed54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -252,12 +252,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
public void AddRow(string sizeNamePrefix)
{
// Without validation we get warning CA1062 when unsing the parameter variable sizeNamePrefix
string prefixString = string.IsNullOrEmpty(sizeNamePrefix) ? "New Size" : sizeNamePrefix;
/// This is a fallback validation to eliminate the warning "CA1062:Validate arguments of public methods" when using the parameter (variable) "sizeNamePrefix" in the code.
/// If the parameter is unexpectedly empty or null, we fill the parameter with a non-localized string.
/// Normally the parameter "sizeNamePrefix" can't be null or empty because it is filled with a localized string when we call this method from <see cref="UI.Views.ImageResizerPage.AddSizeButton_Click"/>.
sizeNamePrefix = string.IsNullOrEmpty(sizeNamePrefix) ? "New Size" : sizeNamePrefix;
ObservableCollection<ImageSize> imageSizes = Sizes;
int maxId = imageSizes.Count > 0 ? imageSizes.OrderBy(x => x.Id).Last().Id : -1;
string sizeName = GenerateNameForNewSize(imageSizes, prefixString);
string sizeName = GenerateNameForNewSize(imageSizes, sizeNamePrefix);
ImageSize newSize = new ImageSize(maxId + 1, sizeName, ResizeFit.Fit, 854, 480, ResizeUnit.Pixel);
newSize.PropertyChanged += SizePropertyChanged;