Example #1
0
    public static IObjectFieldDescriptor ResolveWith <TResolver, TResult>(
        this IObjectFieldDescriptor descriptor,
        Expression <Func <TResolver, Task <TResult?> > > propertyOrMethod)
    {
        if (descriptor is null)
        {
            throw new ArgumentNullException(nameof(descriptor));
        }

        if (propertyOrMethod is null)
        {
            throw new ArgumentNullException(nameof(propertyOrMethod));
        }

        UnaryExpression?convertedBody = Expression.Convert(propertyOrMethod.Body, typeof(object));
        var             newExpression = Expression.Lambda <Func <TResolver, object?> >(convertedBody,
                                                                                       propertyOrMethod.Parameters);

        return(descriptor.ResolveWith(newExpression));
    }