Esempio n. 1
0
 private void TryAddMethodResolver(
     MemberResolverBinding binding,
     List <FieldResolverDescriptor> resolverDescriptors)
 {
     if (binding.FieldMember is MethodInfo m)
     {
         FieldReference fieldReference = new FieldReference(binding.TypeName, binding.FieldName);
         bool           isAsync        = typeof(Task).IsAssignableFrom(m.ReturnType);
         IReadOnlyCollection <FieldResolverArgumentDescriptor> argumentDescriptors =
             FieldResolverDiscoverer.CreateResolverArgumentDescriptors(
                 m, m.ReflectedType, m.ReflectedType);
         resolverDescriptors.Add(FieldResolverDescriptor.CreateSourceMethod(
                                     fieldReference, m.ReflectedType, m, isAsync,
                                     argumentDescriptors));
     }
 }
Esempio n. 2
0
        private IEnumerable <FieldResolver> CompileResolvers()
        {
            List <FieldResolverDescriptor> resolverDescriptors =
                new List <FieldResolverDescriptor>();

            foreach (MemberResolverBinding binding in _resolverBindings.Values
                     .OfType <MemberResolverBinding>())
            {
                if (binding.FieldMember is PropertyInfo p)
                {
                    FieldReference fieldReference = new FieldReference(
                        binding.TypeName, binding.FieldName);
                    resolverDescriptors.Add(FieldResolverDescriptor
                                            .CreateSourceProperty(fieldReference, p.ReflectedType, p));
                }

                if (binding.FieldMember is MethodInfo m)
                {
                    FieldReference fieldReference = new FieldReference(binding.TypeName, binding.FieldName);
                    bool           isAsync        = typeof(Task).IsAssignableFrom(m.ReturnType);
                    IReadOnlyCollection <FieldResolverArgumentDescriptor> argumentDescriptors =
                        FieldResolverDiscoverer.CreateResolverArgumentDescriptors(
                            m, m.ReflectedType, m.ReflectedType);
                    resolverDescriptors.Add(FieldResolverDescriptor.CreateSourceMethod(
                                                fieldReference, m.ReflectedType, m, isAsync,
                                                argumentDescriptors));
                }
            }
            resolverDescriptors.AddRange(_resolverDescriptors.Values);

            if (resolverDescriptors.Any())
            {
                return(_resolverBuilder.Build(resolverDescriptors));
            }
            return(Enumerable.Empty <FieldResolver>());
        }