ChainExecutor.NetCoreApp
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ChainExecutor.NetCoreApp --version 1.0.1
NuGet\Install-Package ChainExecutor.NetCoreApp -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ChainExecutor.NetCoreApp" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ChainExecutor.NetCoreApp" Version="1.0.1" />
<PackageReference Include="ChainExecutor.NetCoreApp" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ChainExecutor.NetCoreApp --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ChainExecutor.NetCoreApp, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ChainExecutor.NetCoreApp@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ChainExecutor.NetCoreApp&version=1.0.1
#tool nuget:?package=ChainExecutor.NetCoreApp&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ChainExecutor
详细可以见 ChainExecutor.Test中的调用
/// <summary>
/// 测试同步链式调用 + 缓存
/// </summary>
/// <param name="cacheKey">缓存Key</param>
static async Task TestSyncChainWithCache(string cacheKey)
{
var result = new ChainExecutor<User>()
.Comment("初始化")
.InitData(new User { Id = 1, Name = "张三", Age = 25 })
.Comment("校验")
.ValidateData(user => user?.Age >= 18)
.Comment("业务处理")
.ProcessBusiness(user =>
{
if (user != null)
{
user.Name = $"[{user.Name}] - 已实名认证(同步处理)";
System.Threading.Thread.Sleep(300); // 模拟耗时业务
}
})
.Execute();
// 打印结果
PrintTestResult(result);
}
/// <summary>
/// 测试异步链式调用 + 自定义验证异常
/// </summary>
static async Task TestAsyncChainWithCustomException()
{
var result = await new ChainExecutor<User>()
.CommentAsync("初始化数据").GetAwaiter().GetResult()
.InitDataAsync(async () =>
{
await Task.Delay(200); // 模拟异步查询数据
return new User { Id = 2, Name = "李四", Age = 17 }; // 年龄不足18,触发验证异常
}).GetAwaiter().GetResult()
.CommentAsync("校验").GetAwaiter().GetResult()
.ValidateDataAsync(async (user) =>
{
await Task.Delay(100); // 模拟异步验证
return user?.Age >= 18;
}).GetAwaiter().GetResult()
.ProcessBusinessAsync(async (user) =>
{
await Task.Delay(200); // 模拟异步更新数据
if (user != null) user.Name = $"[{user.Name}] - 已实名认证(异步处理)";
}).GetAwaiter().GetResult()
.ExecuteAsync();
// 打印结果
PrintTestResult(result);
}
/// <summary>
/// 通用测试结果打印方法
/// </summary>
/// <typeparam name="T">数据类型</typeparam>
/// <param name="result">执行结果</param>
static void PrintTestResult<T>(ChainExecuteResult<T> result) where T : class, new()
{
Console.WriteLine($"\n----- 结果汇总 -----");
Console.WriteLine($"执行状态:{(result.IsSuccess ? "✅ 成功" : "❌ 失败")}");
if (!result.IsSuccess)
{
Console.WriteLine($"错误信息:{result.ErrorMessage}");
return;
}
// 打印业务数据(仅User类型)
if (result.Data is User user)
{
Console.WriteLine($"用户ID:{user.Id}");
Console.WriteLine($"用户姓名:{user.Name}");
Console.WriteLine($"用户年龄:{user.Age}");
}
// 打印前3条日志(简化输出,如需完整日志可遍历全部)
Console.WriteLine($"\n----- 前3条执行日志 -----");
var logCount = Math.Min(3, result.ExecuteLogs.Count);
for (int i = 0; i < logCount; i++)
{
Console.WriteLine(result.ExecuteLogs[i]);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.