mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 17:21:16 +08:00
- 清理 GFramework.Core 与 GFramework.Cqrs 中的大量低风险 Meziantou 警告 - 修复 GFramework.Godot 运行时中的 ConfigureAwait、StringComparison 与参数校验告警 - 调整 Core SourceGenerators 中的字符串比较、文件命名与局部长方法问题 - 拆分部分配置与缓存辅助类型文件以消除 file/type mismatch 告警 - 更新 warning reduction 跟踪与执行记录,保留下一批结构性告警的恢复点
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using GFramework.Core.Abstractions.Query;
|
|
using GFramework.Core.Abstractions.Rule;
|
|
|
|
namespace GFramework.Core.Extensions;
|
|
|
|
/// <summary>
|
|
/// 提供对 IContextAware 接口的查询执行扩展方法
|
|
/// </summary>
|
|
public static class ContextAwareQueryExtensions
|
|
{
|
|
/// <summary>
|
|
/// 发送一个查询请求
|
|
/// </summary>
|
|
/// <typeparam name="TResult">查询结果类型</typeparam>
|
|
/// <param name="contextAware">实现 IContextAware 接口的对象</param>
|
|
/// <param name="query">要发送的查询</param>
|
|
/// <returns>查询结果</returns>
|
|
/// <exception cref="ArgumentNullException">当 contextAware 或 query 为 null 时抛出</exception>
|
|
public static TResult SendQuery<TResult>(this IContextAware contextAware, IQuery<TResult> query)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(contextAware);
|
|
ArgumentNullException.ThrowIfNull(query);
|
|
|
|
var context = contextAware.GetContext();
|
|
return context.SendQuery(query);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 异步发送一个查询请求
|
|
/// </summary>
|
|
/// <typeparam name="TResult">查询结果类型</typeparam>
|
|
/// <param name="contextAware">实现 IContextAware 接口的对象</param>
|
|
/// <param name="query">要发送的异步查询</param>
|
|
/// <returns>查询结果</returns>
|
|
/// <exception cref="ArgumentNullException">当 contextAware 或 query 为 null 时抛出</exception>
|
|
public static async Task<TResult> SendQueryAsync<TResult>(this IContextAware contextAware,
|
|
IAsyncQuery<TResult> query)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(contextAware);
|
|
ArgumentNullException.ThrowIfNull(query);
|
|
|
|
var context = contextAware.GetContext();
|
|
return await context.SendQueryAsync(query).ConfigureAwait(false);
|
|
}
|
|
}
|