健壮性优化

This commit is contained in:
龙腾猫跃 committed 2026-06-28 23:57:37 +08:00
1 parent fe9fc04c20
commit 0a3b21505a
2 files changed
+11 -3

No files matched your search

+5 -1
View File
@@ -68,6 +68,7 @@ public abstract class RedoableWorkerBase<TOut>(Func<CancellationToken?, Progress
public TOut LastResult {
get {
lock (this) {
if (typeof(TOut) == typeof(NoType)) throw new InvalidOperationException("该 Worker 没有返回值。");
if (!hasSucceeded) throw new InvalidOperationException("从未成功完成过。");
return lastResult == null ? default! : (TOut) lastResult;
}
@@ -196,7 +197,7 @@ public class RedoableWorker<TOut> : RedoableWorkerBase<TOut> {
}
/// <inheritdoc />
public class RedoableWorker : RedoableWorkerBase<object?> {
public class RedoableWorker : RedoableWorkerBase<NoType?> {
public RedoableWorker(Action<CancellationToken?, ProgressProvider?> workload, [CallerMemberName] string creatorMemberName = "")
: base((c, p) => { workload(c, p); return null; }, creatorMemberName: creatorMemberName) { }
public RedoableWorker(Action<CancellationToken?> workload, [CallerMemberName] string creatorMemberName = "")
@@ -204,3 +205,6 @@ public class RedoableWorker : RedoableWorkerBase<object?> {
public RedoableWorker(Action workload, [CallerMemberName] string creatorMemberName = "")
: base((_, _) => { workload(); return null; }, creatorMemberName: creatorMemberName) { }
}
/// <summary>指示没有该类型,用于泛型参数。</summary>
public class NoType { }