// 根據委託指向的方法時候包含
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);
}