Giter Club home page Giter Club logo

argumentativefilters's Introduction

Hi, I'm Hugo ๐Ÿฆ€

Professionally I'm a primarily back-end developer using dotnet on AWS.

Aside from that I love C++ and Rust, and enjoy Embedded Systems, Security and Graphics programming.

Stats

hwoodiwiss's github stats

Top Langs

argumentativefilters's People

Contributors

dependabot[bot] avatar hwoodiwiss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

argumentativefilters's Issues

Add "Argument ref" parameters

From looking at the example in the README, it looks like a nice feature would be to have an attribute that could only be used with a ref parameter.

So the example would become this:

public static partial class ExampleFilter
{
    [ArgumentativeFilter]
    public static ValueTask<object?> NormalizeParameterCase(EndpointFilterInvocationContext context, EndpointFilterDelegate next, [ArgumentRef] ref string parameter)
    {
        parameter = parameter.ToUpperInvariant();
        return next(context);
    }
}

The code gen would ref return the value from the context.Arguments array behind the scenes, reusing the existing IndexOf functionality.

Does not add `using`s for provided types

At the moment, using aren't being added to the generated factory code for the types provided in the filter.

This will cause build errors an all but fairly trivial cases.

Example with annotated failures:

// <auto-generated/>
using global::System;
using global::Microsoft.AspNetCore.Http;

#nullable enable

namespace SomeNamespace.Filters
{
    public static partial class SomeRequestValidationFilter
    {
        public static EndpointFilterDelegate Factory(EndpointFilterFactoryContext context, EndpointFilterDelegate next)
        {
            int? argumentNameIndex = context.GetArgumentIndex("argumentName");
            if (argumentNameIndex.HasValue)
            {
                return invocationFilterContext => {
                    var applicationOptionsService = invocationFilterContext.HttpContext.RequestServices.GetService<SomeOptions>(); <- This fails, missing Microsoft.Extensions.DependencyInjection and namespace for SomeOptions
                    var requestContextService = invocationFilterContext.HttpContext.RequestServices.GetService<SomeRequestContext>(); <- This fails, missing Microsoft.Extensions.DependencyInjection and namespace SomeRequestContext
                    var clientContextService = invocationFilterContext.HttpContext.RequestServices.GetService<SomeClientContext>();
                    var someApiOptionsService = invocationFilterContext.HttpContext.RequestServices.GetService<SomeApiOptions>();
                    string argumentValue = invocationFilterContext.GetArgument<string>(argumentNameIndex.Value);
                    return Filter(invocationFilterContext, next, applicationOptionsService, requestContextService, clientContextService, someApiOptionsService , argumentValue);
                };
            }

            return next;
        }

        private static int? GetArgumentIndex(this EndpointFilterFactoryContext context, string argumentName) 
            => context.MethodInfo.GetParameters().FirstOrDefault(p => string.Equals(p.Name, argumentName, StringComparison.Ordinal))?.Position;
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.