Files
TouchSocket/examples/Dmtp/CustomDmtpActorConsoleApp/SimpleDmtpRpc/Extensions/SimpleDmtpRpcExtension.cs
2025-04-26 12:19:17 +08:00

59 lines
2.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.

//------------------------------------------------------------------------------
// 此代码版权除特别声明或在XREF结尾的命名空间的代码归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议若本仓库没有设置则按MIT开源协议授权
// CSDN博客https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频https://space.bilibili.com/94253567
// Gitee源代码仓库https://gitee.com/RRQM_Home
// Github源代码仓库https://github.com/RRQM
// API首页https://touchsocket.net/
// 交流QQ群234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
using TouchSocket.Core;
using TouchSocket.Dmtp;
namespace CustomDmtpActorConsoleApp.SimpleDmtpRpc;
internal static class SimpleDmtpRpcExtension
{
#region
/// <summary>
/// 使用SimpleDmtpRpc插件
/// </summary>
/// <param name="pluginManager"></param>
/// <returns></returns>
public static SimpleDmtpRpcFeature UseSimpleDmtpRpc(this IPluginManager pluginManager)
{
return pluginManager.Add<SimpleDmtpRpcFeature>();
}
#endregion
/// <summary>
/// 从<see cref="DmtpActor"/>中获取<see cref="ISimpleDmtpRpcActor"/>
/// </summary>
/// <param name="smtpActor"></param>
/// <returns></returns>
public static ISimpleDmtpRpcActor GetSimpleDmtpRpcActor(this IDmtpActor smtpActor)
{
return smtpActor.GetActor<SimpleDmtpRpcActor>();
}
/// <summary>
/// 从<see cref="IDmtpActorObject"/>中获取<see cref="ISimpleDmtpRpcActor"/>以实现Rpc调用功能。
/// </summary>
/// <param name="client"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static ISimpleDmtpRpcActor GetSimpleDmtpRpcActor(this IDmtpActorObject client)
{
var smtpRpcActor = client.DmtpActor.GetSimpleDmtpRpcActor();
if (smtpRpcActor is null)
{
throw new ArgumentNullException(nameof(smtpRpcActor), "SimpleRpcAcotr为空请检查是否已启用UseSimpleDmtpRpc");
}
return smtpRpcActor;
}
}