Skip to content

Commit eaad170

Browse files
committed
feat: 增加基类重置方法
1 parent 77a5590 commit eaad170

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/BootstrapBlazor/Components/ErrorLogger/BootstrapBlazorErrorBoundary.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Components.Rendering;
77
using Microsoft.Extensions.Configuration;
88
using Microsoft.Extensions.Logging;
9+
using System.Reflection;
910

1011
namespace BootstrapBlazor.Components;
1112

@@ -71,10 +72,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
7172
var ex = CurrentException ?? _exception;
7273
if (ex != null)
7374
{
74-
_exception = null;
75-
7675
// 处理自定义异常逻辑
77-
if(OnErrorHandleAsync != null)
76+
if (OnErrorHandleAsync != null)
7877
{
7978
// 页面生命周期内异常直接调用这里
8079
_ = OnErrorHandleAsync(Logger, ex);
@@ -83,6 +82,9 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
8382

8483
// 渲染异常内容
8584
builder.AddContent(0, ExceptionContent(ex));
85+
86+
// 重置 CurrentException
87+
ResetException();
8688
}
8789
else
8890
{
@@ -91,6 +93,16 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
9193
}
9294
}
9395

96+
private PropertyInfo? _currentExceptionPropertyInfo;
97+
98+
private void ResetException()
99+
{
100+
_exception = null;
101+
102+
_currentExceptionPropertyInfo ??= GetType().BaseType!.GetProperty(nameof(CurrentException), BindingFlags.NonPublic | BindingFlags.Instance);
103+
_currentExceptionPropertyInfo?.SetValue(this, null);
104+
}
105+
94106
private Exception? _exception = null;
95107

96108
private RenderFragment<Exception> ExceptionContent => ex => builder =>

0 commit comments

Comments
 (0)