-
-
Notifications
You must be signed in to change notification settings - Fork 381
feat(DynamicElement): implement IDisposeAsync interface #7896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ namespace BootstrapBlazor.Components; | |
| /// <para lang="zh">动态元素组件</para> | ||
| /// <para lang="en">Dynamic element component</para> | ||
| /// </summary> | ||
| public class DynamicElement : BootstrapComponentBase | ||
| public class DynamicElement : BootstrapComponentBase, IAsyncDisposable | ||
| { | ||
| /// <summary> | ||
| /// <para lang="zh">获得/设置 TagName 属性 默认为 div</para> | ||
|
|
@@ -176,4 +176,29 @@ private async Task OnTriggerContextMenu(MouseEventArgs e) | |
| await OnContextMenu(e); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <para lang="zh">异步释放资源</para> | ||
| /// <para lang="en">Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously</para> | ||
| /// </summary> | ||
| /// <param name="disposing"></param> | ||
| protected virtual async ValueTask DisposeAsync(bool disposing) | ||
| { | ||
| if (disposing) | ||
| { | ||
| OnClick = null; | ||
| OnDoubleClick = null; | ||
| OnContextMenu = null; | ||
| ChildContent = null; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// <inheritdoc/> | ||
| /// </summary> | ||
| public async ValueTask DisposeAsync() | ||
| { | ||
| await DisposeAsync(true); | ||
| GC.SuppressFinalize(this); | ||
| } | ||
|
Comment on lines
+199
to
+203
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DisposeAsync(bool disposing)is markedasyncbut contains noawait. This will trigger CS1998 and also allocates an unnecessary async state machine on every dispose. Since the method only clears references, make it non-asyncand return a completedValueTask(or make itValueTaskreturning withoutasync).