Skip to content

Commit f559e9e

Browse files
authored
feat(DynamicElement): implement IDisposeAsync interface (#7896)
* doc: 更新资源文件 * feat(DynamicElement): 增加委托销毁逻辑
1 parent c2dcc2e commit f559e9e

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
namespace BootstrapBlazor.Components;
99

1010
/// <summary>
11-
/// <para lang="zh">Bootstrap Blazor JavaScript 隔离基类</para>
12-
/// <para lang="en">Bootstrap blazor JavaScript isolation base class</para>
11+
/// <para lang="zh">BootstrapBlazor JavaScript 隔离基类</para>
12+
/// <para lang="en">BootstrapBlazor JavaScript isolation base class</para>
1313
/// </summary>
1414
public abstract class BootstrapModuleComponentBase : IdComponentBase, IAsyncDisposable
1515
{
@@ -198,7 +198,7 @@ protected async Task InvokeVoidAsync(string identifier, CancellationToken cancel
198198
}
199199

200200
/// <summary>
201-
/// <para lang="zh">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously</para>
201+
/// <para lang="zh">异步释放资源</para>
202202
/// <para lang="en">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously</para>
203203
/// </summary>
204204
/// <param name="disposing"></param>

src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace BootstrapBlazor.Components;
1212
/// <para lang="zh">动态元素组件</para>
1313
/// <para lang="en">Dynamic element component</para>
1414
/// </summary>
15-
public class DynamicElement : BootstrapComponentBase
15+
public class DynamicElement : BootstrapComponentBase, IAsyncDisposable
1616
{
1717
/// <summary>
1818
/// <para lang="zh">获得/设置 TagName 属性 默认为 div</para>
@@ -176,4 +176,29 @@ private async Task OnTriggerContextMenu(MouseEventArgs e)
176176
await OnContextMenu(e);
177177
}
178178
}
179+
180+
/// <summary>
181+
/// <para lang="zh">异步释放资源</para>
182+
/// <para lang="en">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously</para>
183+
/// </summary>
184+
/// <param name="disposing"></param>
185+
protected virtual async ValueTask DisposeAsync(bool disposing)
186+
{
187+
if (disposing)
188+
{
189+
OnClick = null;
190+
OnDoubleClick = null;
191+
OnContextMenu = null;
192+
ChildContent = null;
193+
}
194+
}
195+
196+
/// <summary>
197+
/// <inheritdoc/>
198+
/// </summary>
199+
public async ValueTask DisposeAsync()
200+
{
201+
await DisposeAsync(true);
202+
GC.SuppressFinalize(this);
203+
}
179204
}

0 commit comments

Comments
 (0)