mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 将所有小写的命名空间导入更正为首字母大写格式 - 统一 GFramework 框架的命名空间引用规范 - 修复 core、ecs、godot 等模块的命名空间导入错误 - 标准化文档示例代码中的 using 语句格式 - 确保所有文档中的命名空间引用保持一致性 - 更新 global using 语句以匹配正确的命名空间格式
47 lines
2.0 KiB
C#
47 lines
2.0 KiB
C#
using GFramework.Core.Abstractions.Rule;
|
|
using Mediator;
|
|
|
|
namespace GFramework.Core.Extensions;
|
|
|
|
/// <summary>
|
|
/// 提供对 IContextAware 接口的 Mediator 查询扩展方法
|
|
/// 使用 Mediator 库的查询模式
|
|
/// </summary>
|
|
public static class ContextAwareMediatorQueryExtensions
|
|
{
|
|
/// <summary>
|
|
/// [Mediator] 发送查询的同步版本(不推荐,仅用于兼容性)
|
|
/// </summary>
|
|
/// <typeparam name="TResponse">查询响应类型</typeparam>
|
|
/// <param name="contextAware">实现 IContextAware 接口的对象</param>
|
|
/// <param name="query">要发送的查询对象</param>
|
|
/// <returns>查询结果</returns>
|
|
/// <exception cref="ArgumentNullException">当 contextAware 或 query 为 null 时抛出</exception>
|
|
public static TResponse SendQuery<TResponse>(this IContextAware contextAware, IQuery<TResponse> query)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(contextAware);
|
|
ArgumentNullException.ThrowIfNull(query);
|
|
|
|
var context = contextAware.GetContext();
|
|
return context.SendQuery(query);
|
|
}
|
|
|
|
/// <summary>
|
|
/// [Mediator] 异步发送查询并返回结果
|
|
/// </summary>
|
|
/// <typeparam name="TResponse">查询响应类型</typeparam>
|
|
/// <param name="contextAware">实现 IContextAware 接口的对象</param>
|
|
/// <param name="query">要发送的查询对象</param>
|
|
/// <param name="cancellationToken">取消令牌,用于取消操作</param>
|
|
/// <returns>包含查询结果的ValueTask</returns>
|
|
/// <exception cref="ArgumentNullException">当 contextAware 或 query 为 null 时抛出</exception>
|
|
public static ValueTask<TResponse> SendQueryAsync<TResponse>(this IContextAware contextAware,
|
|
IQuery<TResponse> query, CancellationToken cancellationToken = default)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(contextAware);
|
|
ArgumentNullException.ThrowIfNull(query);
|
|
|
|
var context = contextAware.GetContext();
|
|
return context.SendQueryAsync(query, cancellationToken);
|
|
}
|
|
} |