Пример #1
0
        /// <summary>
        /// Create a delegate from an asynchronous (non-cancellable) action.
        /// </summary>
        /// <typeparam name="TAttributed">Type of object that contains methods marked with [QueryHandler].</typeparam>
        /// <typeparam name="TQuery">Type of query that is handled by the QueryHandlerDelegate.</typeparam>
        /// <typeparam name="TResult">Query's result type.</typeparam>
        /// <param name="attributedObjectFactory">Factory delegate which produces an instance of <typeparamref name="TAttributed"/>.</param>
        /// <returns>Instance of QueryHandlerDelegate.</returns>
        private QueryHandlerDelegate <TResult> createNonCancellableAsyncDelegate <TAttributed, TQuery, TResult>(Func <TAttributed> attributedObjectFactory)
            where TAttributed : class
            where TQuery : class, IQuery <TResult>
        {
            Func <TAttributed, TQuery, Task <TResult> > asyncFunc = (Func <TAttributed, TQuery, Task <TResult> >)MethodInfo.CreateDelegate(typeof(Func <TAttributed, TQuery, Task <TResult> >));

            return(QueryHandlerDelegateBuilder.FromDelegate(attributedObjectFactory, asyncFunc));
        }
Пример #2
0
        /// <summary>
        /// Create a delegate from a synchronous action.
        /// </summary>
        /// <typeparam name="TAttributed">Type of object that contains methods marked with [QueryHandler].</typeparam>
        /// <typeparam name="TQuery">Type of query that is handled by the QueryHandlerDelegate.</typeparam>
        /// <typeparam name="TResult">Query's result type.</typeparam>
        /// <param name="attributedObjectFactory">Factory delegate which produces an instance of <typeparamref name="TAttributed"/>.</param>
        /// <returns>Instance of QueryHandlerDelegate.</returns>
        private QueryHandlerDelegate <TResult> createWrappedSyncDelegate <TAttributed, TQuery, TResult>(Func <TAttributed> attributedObjectFactory)
            where TAttributed : class
            where TQuery : class, IQuery <TResult>
        {
            Func <TAttributed, TQuery, TResult> func = (Func <TAttributed, TQuery, TResult>)MethodInfo.CreateDelegate(typeof(Func <TAttributed, TQuery, TResult>));

            return(QueryHandlerDelegateBuilder.FromDelegate(attributedObjectFactory, func));
        }