Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita2538ea

Browse files
committed
chore: use MulticastExceptionHandler
1 parentb4f2f46 commita2538ea

File tree

1 file changed

+76
-31
lines changed

1 file changed

+76
-31
lines changed

‎src/Prism.Core/Dialogs/DialogCallback.cs‎

Lines changed: 76 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
usingSystem.ComponentModel;
44
usingSystem.Linq;
55
usingSystem.Threading.Tasks;
6+
usingPrism.Common;
67

78
namespacePrism.Dialogs;
89

@@ -13,8 +14,8 @@ namespace Prism.Dialogs;
1314
publicreadonlystructDialogCallback
1415
{
1516
privatereadonlybool_empty=false;
16-
privatereadonlyList<MulticastDelegate>_callbacks=newList<MulticastDelegate>();
17-
privatereadonlyList<MulticastDelegate>_errorCallbacks=newList<MulticastDelegate>();
17+
privatereadonlyList<MulticastDelegate>_callbacks=new();
18+
privatereadonlyMulticastExceptionHandler_errorCallbacks=new();
1819

1920
/// <summary>
2021
/// Creates a new instance of a DialogCallback
@@ -24,7 +25,10 @@ public DialogCallback()
2425
{
2526
}
2627

27-
privateDialogCallback(boolempty)=>_empty=empty;
28+
privateDialogCallback(boolempty)
29+
{
30+
_empty=empty;
31+
}
2832

2933
/// <summary>
3034
/// Invokes the Delegates based on a specific Exception that was encountered.
@@ -43,26 +47,21 @@ public Task Invoke(Exception ex) =>
4347
[EditorBrowsable(EditorBrowsableState.Never)]
4448
publicasyncTaskInvoke(IDialogResultresult)
4549
{
46-
if(_empty||(!_callbacks.Any()&&!_errorCallbacks.Any()))
50+
if(_empty)
51+
{
4752
return;
48-
49-
if(result.Exceptionis notnull)
53+
}
54+
elseif(result.Exceptionis notnull&&_errorCallbacks.CanHandle(result.Exception))
5055
{
51-
// process error callbacks
52-
if(_errorCallbacks.Any())
53-
{
54-
foreach(MulticastDelegateerrorCallbackin_errorCallbacks)
55-
{
56-
awaitProcess(errorCallback,result);
57-
}
58-
return;
59-
}
56+
await_errorCallbacks.HandleAsync(result.Exception,result);
57+
return;
6058
}
61-
62-
63-
foreach(varcallbackin_callbacks)
59+
elseif(_callbacks.Any())
6460
{
65-
awaitProcess(callback,result);
61+
foreach(varcallbackin_callbacks)
62+
{
63+
awaitProcess(callback,result);
64+
}
6665
}
6766
}
6867

@@ -72,14 +71,10 @@ private static async Task Process(MulticastDelegate @delegate, IDialogResult res
7271
action();
7372
elseif(@delegateisAction<IDialogResult>actionResult)
7473
actionResult(result);
75-
elseif(@delegateisAction<Exception>actionException&&result.Exceptionis notnull)
76-
actionException(result.Exception);
7774
elseif(@delegateisFunc<Task>func)
7875
awaitfunc();
7976
elseif(@delegateisFunc<IDialogResult,Task>funcResult)
8077
awaitfuncResult(result);
81-
elseif(@delegateisFunc<Exception,Task>taskException&&result.Exceptionis notnull)
82-
awaittaskException(result.Exception);
8378
}
8479

8580
/// <summary>
@@ -117,7 +112,19 @@ public DialogCallback OnClose(Action<IDialogResult> action)
117112
/// <returns></returns>
118113
publicDialogCallbackOnError(Actionaction)
119114
{
120-
_errorCallbacks.Add(action);
115+
_errorCallbacks.Register<Exception>(action);
116+
returnthis;
117+
}
118+
119+
/// <summary>
120+
/// Provides a delegate callback method when an Exception is encountered
121+
/// </summary>
122+
/// <param name="action">The callback</param>
123+
/// <returns></returns>
124+
publicDialogCallbackOnError<TException>(Actionaction)
125+
whereTException:Exception
126+
{
127+
_errorCallbacks.Register<TException>(action);
121128
returnthis;
122129
}
123130

@@ -128,7 +135,19 @@ public DialogCallback OnError(Action action)
128135
/// <returns></returns>
129136
publicDialogCallbackOnError(Action<Exception>action)
130137
{
131-
_errorCallbacks.Add(action);
138+
_errorCallbacks.Register<Exception>(action);
139+
returnthis;
140+
}
141+
142+
/// <summary>
143+
/// Provides a delegate callback method when an Exception is encountered
144+
/// </summary>
145+
/// <param name="action">The callback</param>
146+
/// <returns></returns>
147+
publicDialogCallbackOnError<TException>(Action<TException>action)
148+
whereTException:Exception
149+
{
150+
_errorCallbacks.Register<TException>(action);
132151
returnthis;
133152
}
134153

@@ -137,9 +156,10 @@ public DialogCallback OnError(Action<Exception> action)
137156
/// </summary>
138157
/// <param name="action">The callback</param>
139158
/// <returns></returns>
140-
publicDialogCallbackOnError(Action<IDialogResult>action)
159+
publicDialogCallbackOnError<TException>(Action<TException,IDialogResult>action)
160+
whereTException:Exception
141161
{
142-
_errorCallbacks.Add(action);
162+
_errorCallbacks.Register<TException>(action);
143163
returnthis;
144164
}
145165

@@ -172,7 +192,19 @@ public DialogCallback OnCloseAsync(Func<IDialogResult, Task> func)
172192
/// <returns></returns>
173193
publicDialogCallbackOnErrorAsync(Func<Task>func)
174194
{
175-
_errorCallbacks.Add(func);
195+
_errorCallbacks.Register<Exception>(func);
196+
returnthis;
197+
}
198+
199+
/// <summary>
200+
/// Provides an asynchronous delegate callback method when an Exception is encountered
201+
/// </summary>
202+
/// <param name="func">The callback</param>
203+
/// <returns></returns>
204+
publicDialogCallbackOnErrorAsync<TException>(Func<Task>func)
205+
whereTException:Exception
206+
{
207+
_errorCallbacks.Register<TException>(func);
176208
returnthis;
177209
}
178210

@@ -183,7 +215,19 @@ public DialogCallback OnErrorAsync(Func<Task> func)
183215
/// <returns></returns>
184216
publicDialogCallbackOnErrorAsync(Func<Exception,Task>func)
185217
{
186-
_errorCallbacks.Add(func);
218+
_errorCallbacks.Register<Exception>(func);
219+
returnthis;
220+
}
221+
222+
/// <summary>
223+
/// Provides an asynchronous delegate callback method when an Exception is encountered
224+
/// </summary>
225+
/// <param name="func">The callback</param>
226+
/// <returns></returns>
227+
publicDialogCallbackOnErrorAsync<TException>(Func<TException,Task>func)
228+
whereTException:Exception
229+
{
230+
_errorCallbacks.Register<TException>(func);
187231
returnthis;
188232
}
189233

@@ -192,9 +236,10 @@ public DialogCallback OnErrorAsync(Func<Exception, Task> func)
192236
/// </summary>
193237
/// <param name="func">The callback</param>
194238
/// <returns></returns>
195-
publicDialogCallbackOnErrorAsync(Func<IDialogResult,Task>func)
239+
publicDialogCallbackOnErrorAsync<TException>(Func<TException,IDialogResult,Task>func)
240+
whereTException:Exception
196241
{
197-
_errorCallbacks.Add(func);
242+
_errorCallbacks.Register<TException>(func);
198243
returnthis;
199244
}
200245
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp