@@ -76,6 +76,54 @@ public static Task<TReturn> InvokeTask<TReturn, TArgument>(string globalIdentifi
7676 : throw new KeyNotFoundException ( $ "There is no task with identifier '{ globalIdentifier } '.") ;
7777 }
7878 }
79+
80+ /// <summary>
81+ /// 上下文中与 Flow 任务相关的扩展方法
82+ /// </summary>
83+ /// <param name="context">作用域上下文</param>
84+ extension( ScopeContext context )
85+ {
86+ /// <summary>
87+ /// 调用既无参数也无返回值的 Flow 任务,详情参考 <see cref="InvokeTask{TReturn, TArgument}(string, TArgument)"/>。
88+ /// </summary>
89+ public Task InvokeTask ( string identifier )
90+ => context . InvokeTask < None , None > ( identifier , default ) ;
91+
92+ /// <summary>
93+ /// 调用无参数的 Flow 任务,详情参考 <see cref="InvokeTask{TReturn, TArgument}(string, TArgument)"/>。
94+ /// </summary>
95+ public Task < TReturn > InvokeTask < TReturn > ( string identifier )
96+ => context . InvokeTask < TReturn , None > ( identifier , default ) ;
97+
98+ /// <summary>
99+ /// 调用无返回值的 Flow 任务,详情参考 <see cref="InvokeTask{TReturn, TArgument}(string, TArgument)"/>。
100+ /// </summary>
101+ public Task InvokeTask < TArgument > ( string identifier , TArgument argument )
102+ => context . InvokeTask < None , TArgument > ( identifier , argument ) ;
103+
104+ /// <summary>
105+ /// 调用 Flow 任务,传入参数并获取返回值。<br/>
106+ /// 当 <see cref="Flow.EnableTaskInvokingInfo"/> 为 <see langword="true"/>
107+ /// 时,使用该方法及其变体调用任务会产生包含调用方和目标标识符的调用信息。
108+ /// <b>NOTE</b>: 没有返回值或没有参数时用默认的 <see cref="None"/> 类型替代。
109+ /// </summary>
110+ /// <param name="identifier">任务标识符,可传入相对于当前作用域的短标识符,或包含作用域前缀的完整标识符</param>
111+ /// <param name="argument">任务参数,若大于一个,则该值应传入 <see cref="ValueTuple"/></param>
112+ /// <typeparam name="TReturn">返回值类型</typeparam>
113+ /// <typeparam name="TArgument">参数类型</typeparam>
114+ /// <returns>任务返回值</returns>
115+ /// <exception cref="KeyNotFoundException">不存在指定全局标识的任务</exception>
116+ public Task < TReturn > InvokeTask < TReturn , TArgument > ( string identifier , TArgument argument )
117+ {
118+ var globalIdentifier = $ "{ context . Identifier } :{ identifier } ";
119+ if ( ! ExistsTask ( globalIdentifier ) ) globalIdentifier = identifier ;
120+ var invokingInfo = EnableTaskInvokingInfo ? new FlowTaskInvokingInfo {
121+ DirectCaller = context . Identifier ,
122+ Target = globalIdentifier ,
123+ } : default ;
124+ return Internal . InvokeTask < TReturn , TArgument > ( globalIdentifier , argument , invokingInfo ) ;
125+ }
126+ }
79127}
80128
81129public interface IFlowTask
0 commit comments