Example #1
0
        private bool GetDelegateInformationFromAsyncMethod(string methodName, IDictionary <string, AsyncEventMethodInfo> dictionary)
        {
            // First, try to get a delegate to the single-parameter handler
            MethodInfo parameterfulMethod = GetInstanceMethodInfo(typeof(Func <CancellationToken, Task>), methodName);

            if (parameterfulMethod != null)
            {
                dictionary[methodName] = new AsyncEventMethodInfo(parameterfulMethod, requiresCancellationToken: true);
                return(true);
            }

            // If there isn't one, try the argless one
            MethodInfo parameterlessMethod = GetInstanceMethodInfo(typeof(Func <Task>), methodName);

            if (parameterlessMethod != null)
            {
                dictionary[methodName] = new AsyncEventMethodInfo(parameterlessMethod, requiresCancellationToken: false);
                return(true);
            }

            return(false);
        }
    private bool GetDelegateInformationFromAsyncMethod(string methodName, IDictionary<string, AsyncEventMethodInfo> dictionary) {
        // First, try to get a delegate to the single-parameter handler
        MethodInfo parameterfulMethod = GetInstanceMethodInfo(typeof(Func<CancellationToken, Task>), methodName);
        if (parameterfulMethod != null) {
            dictionary[methodName] = new AsyncEventMethodInfo(parameterfulMethod, requiresCancellationToken: true);
            return true;
        }

        // If there isn't one, try the argless one
        MethodInfo parameterlessMethod = GetInstanceMethodInfo(typeof(Func<Task>), methodName);
        if (parameterlessMethod != null) {
            dictionary[methodName] = new AsyncEventMethodInfo(parameterlessMethod, requiresCancellationToken: false);
            return true;
        }

        return false;
    }