GFramework/framework/extensions/CanSendExtensions.cs
GwWuYou da3941d6af refactor(framework): 重构框架命名空间和项目名称
- 将所有 GWFramework 命名空间重命名为 GFramework
- 更新解决方案文件中的项目名称和路径引用
- 修改项目文件中的 PackageId、Product 和 URL 配置
- 统一框架内各模块的命名空间前缀为 GFramework
- 调整根命名空间配置以匹配新的项目结构
2025-12-09 18:28:55 +08:00

77 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GFramework.framework.command;
using GFramework.framework.events;
using GFramework.framework.query;
namespace GFramework.framework.extensions;
/// <summary>
/// 提供发送命令功能的扩展类
/// </summary>
public static class CanSendCommandExtension
{
/// <summary>
/// 发送指定类型的命令该命令类型必须实现ICommand接口且具有无参构造函数
/// </summary>
/// <typeparam name="T">命令类型必须实现ICommand接口且具有无参构造函数</typeparam>
/// <param name="self">实现ICanSendCommand接口的对象实例</param>
public static void SendCommand<T>(this ICanSendCommand self) where T : ICommand, new() =>
self.GetArchitecture().SendCommand(new T());
/// <summary>
/// 发送指定的命令实例
/// </summary>
/// <typeparam name="T">命令类型必须实现ICommand接口</typeparam>
/// <param name="self">实现ICanSendCommand接口的对象实例</param>
/// <param name="command">要发送的命令实例</param>
public static void SendCommand<T>(this ICanSendCommand self, T command) where T : ICommand =>
self.GetArchitecture().SendCommand(command);
/// <summary>
/// 发送带有返回值的命令并获取执行结果
/// </summary>
/// <typeparam name="TResult">命令执行结果的类型</typeparam>
/// <param name="self">实现ICanSendCommand接口的对象实例</param>
/// <param name="command">要发送的命令实例必须实现ICommand&lt;TResult&gt;接口</param>
/// <returns>命令执行后的返回结果</returns>
public static TResult SendCommand<TResult>(this ICanSendCommand self, ICommand<TResult> command) =>
self.GetArchitecture().SendCommand(command);
}
/// <summary>
/// 提供发送事件功能的扩展类
/// </summary>
public static class CanSendEventExtension
{
/// <summary>
/// 发送指定类型的事件,该事件类型必须具有无参构造函数
/// </summary>
/// <typeparam name="T">事件类型,必须具有无参构造函数</typeparam>
/// <param name="self">实现ICanSendEvent接口的对象实例</param>
public static void SendEvent<T>(this ICanSendEvent self) where T : new() =>
self.GetArchitecture().SendEvent<T>();
/// <summary>
/// 发送指定的事件实例
/// </summary>
/// <typeparam name="T">事件类型</typeparam>
/// <param name="self">实现ICanSendEvent接口的对象实例</param>
/// <param name="e">要发送的事件实例</param>
public static void SendEvent<T>(this ICanSendEvent self, T e) => self.GetArchitecture().SendEvent(e);
}
/// <summary>
/// 提供发送查询功能的扩展类
/// </summary>
public static class CanSendQueryExtension
{
/// <summary>
/// 发送查询请求并获取查询结果
/// </summary>
/// <typeparam name="TResult">查询结果的类型</typeparam>
/// <param name="self">实现ICanSendQuery接口的对象实例</param>
/// <param name="query">要发送的查询实例必须实现IQuery&lt;TResult&gt;接口</param>
/// <returns>查询操作的返回结果</returns>
public static TResult SendQuery<TResult>(this ICanSendQuery self, IQuery<TResult> query) =>
self.GetArchitecture().SendQuery(query);
}