Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Components/Web/src/Forms/InputFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,20 @@ Task IInputFileJsCallbacks.NotifyChange(BrowserFile[] files)
return OnChange.InvokeAsync(new InputFileChangeEventArgs(files));
}

/// <summary>
/// Releases the resources used by the <see cref="InputFile"/> component.
/// </summary>
/// <param name="disposing"><see langword="true"/> if called within <see cref="IDisposable.Dispose"/>.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_jsCallbacksRelay?.Dispose();
}
}

void IDisposable.Dispose()
{
_jsCallbacksRelay?.Dispose();
Dispose(disposing: true);
}
}
1 change: 1 addition & 0 deletions src/Components/Web/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ Microsoft.AspNetCore.Components.Web.Media.MediaSource.MediaSource(byte[]! data,
Microsoft.AspNetCore.Components.Web.Media.MediaSource.MediaSource(System.IO.Stream! stream, string! mimeType, string! cacheKey) -> void
Microsoft.AspNetCore.Components.Web.Media.MediaSource.MimeType.get -> string!
Microsoft.AspNetCore.Components.Web.Media.MediaSource.Stream.get -> System.IO.Stream!
virtual Microsoft.AspNetCore.Components.Forms.InputFile.Dispose(bool disposing) -> void
40 changes: 40 additions & 0 deletions src/Components/Web/test/Forms/InputFileTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.Components.Forms;

public class InputFileTest
{
[Fact]
public void DerivedClass_CanOverrideDisposeMethod()
{
// Arrange
var disposed = false;
var derivedInputFile = new DerivedInputFile(() => disposed = true);

// Act
((IDisposable)derivedInputFile).Dispose();

// Assert
Assert.True(disposed, "Derived class Dispose(bool) method should be called");
}

private class DerivedInputFile : InputFile
{
private readonly Action _onDispose;

public DerivedInputFile(Action onDispose)
{
_onDispose = onDispose;
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
_onDispose();
}
base.Dispose(disposing);
}
}
}
Loading