public static void DiscoverArguments(
            IDescriptorContext context,
            ICollection <ArgumentDefinition> arguments,
            MemberInfo?member)
        {
            if (arguments is null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (member is MethodInfo method)
            {
                var processed = new HashSet <NameString>(
                    arguments.Select(t => t.Name));

                foreach (ParameterInfo parameter in
                         context.ResolverCompiler.GetArgumentParameters(method.GetParameters()))
                {
                    ArgumentDefinition argumentDefinition =
                        ArgumentDescriptor
                        .New(context, parameter)
                        .CreateDefinition();

                    if (processed.Add(argumentDefinition.Name))
                    {
                        arguments.Add(argumentDefinition);
                    }
                }
            }
        }
Esempio n. 2
0
    protected void Argument(
        NameString name,
        Action <IArgumentDescriptor> argument)
    {
        if (argument is null)
        {
            throw new ArgumentNullException(nameof(argument));
        }

        name.EnsureNotEmpty(nameof(name));

        ParameterInfo?parameter = null;

        Parameters?.TryGetValue(name, out parameter);

        ArgumentDescriptor?descriptor = parameter is null
            ? Arguments.FirstOrDefault(t => t.Definition.Name.Equals(name))
            : Arguments.FirstOrDefault(t => t.Definition.Parameter == parameter);

        if (descriptor is null && Definition.Arguments.Count > 0)
        {
            ArgumentDefinition?definition = parameter is null
                ? Definition.Arguments.FirstOrDefault(t => t.Name.Equals(name))
                : Definition.Arguments.FirstOrDefault(t => t.Parameter == parameter);

            if (definition is not null)
            {
                descriptor = ArgumentDescriptor.From(Context, definition);
            }
        }

        if (descriptor is null)
        {
            descriptor = parameter is null
                ? ArgumentDescriptor.New(Context, name)
                : ArgumentDescriptor.New(Context, parameter);

            Arguments.Add(descriptor);
        }

        argument(descriptor);
    }
        private static void HandleObjectType(
            ITypeCompletionContext completionContext,
            ObjectTypeDefinition definition,
            ISpatialConvention convention)
        {
            foreach (var field in definition.Fields)
            {
                foreach (var arg in field.Arguments)
                {
                    if (arg.Type is not null &&
                        completionContext.IsNamedType <IGeoJsonInputType>(arg.Type))
                    {
                        arg.Formatters.Add(
                            new GeometryTransformerInputFormatter(
                                convention.TransformerFactory,
                                convention.DefaultSrid));
                    }
                }

                if (field.Type is not null &&
                    completionContext.IsNamedType <IGeoJsonObjectType>(field.Type))
                {
                    var argument =
                        ArgumentDescriptor.New(
                            completionContext.DescriptorContext,
                            CrsFieldName);

                    argument
                    .Type <IntType>()
                    .Description(Transformation_Argument_Crs_Description);

                    field.Arguments.Add(argument.CreateDefinition());
                    field.MiddlewareDefinitions.Insert(0,
                                                       new(FieldClassMiddlewareFactory.Create <GeometryTransformationMiddleware>(
                                                               (typeof(IGeometryTransformerFactory), convention.TransformerFactory),
                                                               (typeof(int), convention.DefaultSrid))));
                }
            }
        }