Fix string interpolation bugs

This commit is contained in:
Robert McRackan 2022-11-14 15:16:22 -05:00
parent 7575736991
commit bce44b6f6d
6 changed files with 22 additions and 8 deletions

View File

@ -102,6 +102,9 @@ Libation.
".Trim(), "Verbose logging enabled", MessageBoxButtons.OK, MessageBoxIcon.Warning); ".Trim(), "Verbose logging enabled", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
/// <summary>
/// Note: the format field should use {0} and NOT use the `$` string interpolation. Formatting is done inside this method.
/// </summary>
public static async Task<DialogResult> ShowConfirmationDialog(Window owner, IEnumerable<LibraryBook> libraryBooks, string format, string title, MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1) public static async Task<DialogResult> ShowConfirmationDialog(Window owner, IEnumerable<LibraryBook> libraryBooks, string format, string title, MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1)
{ {
if (libraryBooks is null || !libraryBooks.Any()) if (libraryBooks is null || !libraryBooks.Any())

View File

@ -247,7 +247,8 @@ namespace LibationAvalonia.ViewModels
var result = await MessageBox.ShowConfirmationDialog( var result = await MessageBox.ShowConfirmationDialog(
null, null,
libraryBooks, libraryBooks,
$"Are you sure you want to remove {selectedBooks.Count} books from Libation's library?", // do not use `$` string interpolation. See impl.
"Are you sure you want to remove {0} from Libation's library?",
"Remove books from Libation?"); "Remove books from Libation?");
if (result != DialogResult.Yes) if (result != DialogResult.Yes)

View File

@ -50,6 +50,7 @@ namespace LibationAvalonia.Views
var confirmationResult = await MessageBox.ShowConfirmationDialog( var confirmationResult = await MessageBox.ShowConfirmationDialog(
this, this,
visibleLibraryBooks, visibleLibraryBooks,
// do not use `$` string interpolation. See impl.
"Are you sure you want to replace tags in {0}?", "Are you sure you want to replace tags in {0}?",
"Replace tags?"); "Replace tags?");
@ -73,6 +74,7 @@ namespace LibationAvalonia.Views
var confirmationResult = await MessageBox.ShowConfirmationDialog( var confirmationResult = await MessageBox.ShowConfirmationDialog(
this, this,
visibleLibraryBooks, visibleLibraryBooks,
// do not use `$` string interpolation. See impl.
"Are you sure you want to replace downloaded status in {0}?", "Are you sure you want to replace downloaded status in {0}?",
"Replace downloaded status?"); "Replace downloaded status?");
@ -91,6 +93,7 @@ namespace LibationAvalonia.Views
var confirmationResult = await MessageBox.ShowConfirmationDialog( var confirmationResult = await MessageBox.ShowConfirmationDialog(
this, this,
visibleLibraryBooks, visibleLibraryBooks,
// do not use `$` string interpolation. See impl.
"Are you sure you want to remove {0} from Libation's library?", "Are you sure you want to remove {0} from Libation's library?",
"Remove books from Libation?", "Remove books from Libation?",
MessageBoxDefaultButton.Button2); MessageBoxDefaultButton.Button2);

View File

@ -80,6 +80,7 @@ namespace LibationWinForms
var confirmationResult = MessageBoxLib.ShowConfirmationDialog( var confirmationResult = MessageBoxLib.ShowConfirmationDialog(
visibleLibraryBooks, visibleLibraryBooks,
// do not use `$` string interpolation. See impl.
"Are you sure you want to replace tags in {0}?", "Are you sure you want to replace tags in {0}?",
"Replace tags?"); "Replace tags?");
@ -102,7 +103,8 @@ namespace LibationWinForms
var confirmationResult = MessageBoxLib.ShowConfirmationDialog( var confirmationResult = MessageBoxLib.ShowConfirmationDialog(
visibleLibraryBooks, visibleLibraryBooks,
$"Are you sure you want to replace downloaded status in {0}?", // do not use `$` string interpolation. See impl.
"Are you sure you want to replace downloaded status in {0}?",
"Replace downloaded status?"); "Replace downloaded status?");
if (confirmationResult != DialogResult.Yes) if (confirmationResult != DialogResult.Yes)
@ -119,7 +121,8 @@ namespace LibationWinForms
var confirmationResult = MessageBoxLib.ShowConfirmationDialog( var confirmationResult = MessageBoxLib.ShowConfirmationDialog(
visibleLibraryBooks, visibleLibraryBooks,
$"Are you sure you want to remove {0} from Libation's library?", // do not use `$` string interpolation. See impl.
"Are you sure you want to remove {0} from Libation's library?",
"Remove books from Libation?"); "Remove books from Libation?");
if (confirmationResult != DialogResult.Yes) if (confirmationResult != DialogResult.Yes)

View File

@ -109,7 +109,8 @@ namespace LibationWinForms.GridView
var libraryBooks = selectedBooks.Select(rge => rge.LibraryBook).ToList(); var libraryBooks = selectedBooks.Select(rge => rge.LibraryBook).ToList();
var result = MessageBoxLib.ShowConfirmationDialog( var result = MessageBoxLib.ShowConfirmationDialog(
libraryBooks, libraryBooks,
$"Are you sure you want to remove {selectedBooks.Count} books from Libation's library?", // do not use `$` string interpolation. See impl.
"Are you sure you want to remove {0} from Libation's library?",
"Remove books from Libation?"); "Remove books from Libation?");
if (result != DialogResult.Yes) if (result != DialogResult.Yes)

View File

@ -64,6 +64,9 @@ Libation.
".Trim(), "Verbose logging enabled", MessageBoxButtons.OK, MessageBoxIcon.Warning); ".Trim(), "Verbose logging enabled", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
/// <summary>
/// Note: the format field should use {0} and NOT use the `$` string interpolation. Formatting is done inside this method.
/// </summary>
public static DialogResult ShowConfirmationDialog(IEnumerable<LibraryBook> libraryBooks, string format, string title) public static DialogResult ShowConfirmationDialog(IEnumerable<LibraryBook> libraryBooks, string format, string title)
{ {
if (libraryBooks is null || !libraryBooks.Any()) if (libraryBooks is null || !libraryBooks.Any())