// 根据委托指向的方法时候包含
async标记Method.IsDefined(async)
//通用写法
private static bool IsAsyncAppliedToDelegate(Delegate d) { return d.Method.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) != null; }
//例子: 判断 Action 和Func<TResult>
static bool IsThisAsync(Action action) { return action.Method.IsDefined(typeof(AsyncStateMachineAttribute),false); }
static bool IsThisAsync(Func<Task> action) { return action.Method.IsDefined(typeof(AsyncStateMachineAttribute),false); }
判断Action Func 是否是异步方法
最新推荐文章于 2022-08-04 17:01:48 发布