Example #1
0
        private Func <IResolveFieldContext, object> GetResolverFor(Func <IResolveFieldContextT <TSourceType>, object> resolver)
        {
            return(context =>
            {
                object resolved = resolver((IResolveFieldContextT <TSourceType>)context);
                if (resolved == null)
                {
                    return null;
                }

                IResolveFieldContext ctx = (IResolveFieldContext)Activator.CreateInstance(typeof(TResponseType));

                if (resolved.GetType().IsGenericType&& resolved.GetType().IsAssignableTo(typeof(IEnumerable)))
                {
                    List <object> list = new();
                    foreach (object item in (IEnumerable)resolved)
                    {
                        ctx.Source = item;
                        list.Add(ctx.Build());
                    }

                    return list;
                }

                ctx.Source = resolved;
                return ctx.Build();
            });
        }