<commit_before>﻿namespace LinqToQuerystring.WebApi
{
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Net.Http.Formatting;
    using System.Web.Http.Filters;

    using ActionFilterAttribute = System.Web.Http.Filters.ActionFilterAttribute;

    public class LinqToQueryableAttribute : ActionFilterAttribute
    {
        private readonly bool forceDynamicProperties;

        private readonly int maxPageSize;

        public LinqToQueryableAttribute(bool forceDynamicProperties = false, int maxPageSize = -1)
        {
            this.forceDynamicProperties = forceDynamicProperties;
            this.maxPageSize = maxPageSize;
        }

        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            object responseObject;
            actionExecutedContext.Response.TryGetContentValue(out responseObject);
            var originalquery = responseObject as IQueryable;

            if (originalquery != null)
            {
                var queryString = actionExecutedContext.Request.RequestUri.Query;
                var genericType = originalquery.GetType().GetGenericArguments()[0];

                var reply = originalquery.LinqToQuerystring(genericType, queryString, this.forceDynamicProperties, this.maxPageSize);
                var replyType = reply.GetType();

                if (typeof(IQueryable).IsAssignableFrom(replyType))
                {
                    var queryableType = typeof(IQueryable<>).GetGenericTypeDefinition();
                    var genericArgs = replyType.GetGenericArguments();
                    replyType = queryableType.MakeGenericType(genericArgs);
                }

                var configuraton = actionExecutedContext.ActionContext.ControllerContext.Configuration;
                var conneg = (IContentNegotiator)configuraton.Services.GetService(typeof(IContentNegotiator));
                var formatter = conneg.Negotiate(
                    replyType,
                    actionExecutedContext.Request,
                    configuraton.Formatters);

                actionExecutedContext.Response = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content = new ObjectContent(replyType, reply, formatter.Formatter)<commit_msg>Test that this doesn't trigger a core build<commit_after>﻿namespace LinqToQuerystring.WebApi
{
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Net.Http.Formatting;
    using System.Web.Http.Filters;

    using ActionFilterAttribute = System.Web.Http.Filters.ActionFilterAttribute;

    public class LinqToQueryableAttribute : ActionFilterAttribute
    {
        private readonly bool forceDynamicProperties;

        private readonly int maxPageSize;

        public LinqToQueryableAttribute(bool forceDynamicProperties = false, int maxPageSize = -1)
        {
            this.forceDynamicProperties = forceDynamicProperties;
            this.maxPageSize = maxPageSize;
        }

        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            object responseObject;

            actionExecutedContext.Response.TryGetContentValue(out responseObject);
            var originalquery = responseObject as IQueryable;

            if (originalquery != null)
            {
                var queryString = actionExecutedContext.Request.RequestUri.Query;
                var genericType = originalquery.GetType().GetGenericArguments()[0];

                var reply = originalquery.LinqToQuerystring(genericType, queryString, this.forceDynamicProperties, this.maxPageSize);
                var replyType = reply.GetType();

                if (typeof(IQueryable).IsAssignableFrom(replyType))
                {
                    var queryableType = typeof(IQueryable<>).GetGenericTypeDefinition();
                    var genericArgs = replyType.GetGenericArguments();
                    replyType = queryableType.MakeGenericType(genericArgs);
                }

                var configuraton = actionExecutedContext.ActionContext.ControllerContext.Configuration;
                var conneg = (IContentNegotiator)configuraton.Services.GetService(typeof(IContentNegotiator));
                var formatter = conneg.Negotiate(
                    replyType,
                    actionExecutedContext.Request,
                    configuraton.Formatters);

                actionExecutedContext.Response = new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content = new ObjectContent(replyType, reply, formatter.Formatter)
{'fraction_non_alphanumeric': 0.06582010582010582, 'fraction_numerical': 0.0008465608465608466, 'mean_word_length': 2.311843027330063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '974258', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1075, 'n_words': 210}