Handled nullable content and improved null checks in MudCopyClipboardButton.

This commit is contained in:
Thorsten Sommer 2025-08-09 21:42:53 +02:00
parent e4cd2a75a1
commit eca0d33da3
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -48,10 +48,10 @@ public partial class MudCopyClipboardButton : ComponentBase
private async Task HandleCopyClick() private async Task HandleCopyClick()
{ {
if (this.Type == ContentType.NONE) if (this.Type is ContentType.NONE)
await this.CopyToClipboard(this.StringContent); await this.CopyToClipboard(this.StringContent);
else else
await this.CopyToClipboard(this.Content!); await this.CopyToClipboard(this.Content);
} }
/// <summary> /// <summary>
@ -65,8 +65,11 @@ public partial class MudCopyClipboardButton : ComponentBase
/// <summary> /// <summary>
/// Copy this block's content to the clipboard. /// Copy this block's content to the clipboard.
/// </summary> /// </summary>
private async Task CopyToClipboard(IContent contentToCopy) private async Task CopyToClipboard(IContent? contentToCopy)
{ {
if (contentToCopy is null)
return;
switch (this.Type) switch (this.Type)
{ {
case ContentType.TEXT: case ContentType.TEXT: