Skip to content

Commit

Permalink
refactor EvaluateExpression method
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusz96 committed Dec 13, 2023
1 parent 5afd03d commit aede87c
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/UriGeneration/Internal/ValuesExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ internal class ValuesExtractor : IValuesExtractor
private static readonly MemoryCacheEntryOptions CacheEntryOptions =
new() { Size = 1 };

private static readonly ParameterExpression UnusedParameterExpression =
Expression.Parameter(typeof(object), "unused");

private readonly IMethodCacheAccessor _methodCacheAccessor;
private readonly IActionDescriptorCollectionProvider _actionDescriptorsProvider;
private readonly ILogger<ValuesExtractor> _logger;
Expand Down Expand Up @@ -281,13 +278,13 @@ private RouteValueDictionary ExtractRouteValues(
}
else
{
// See: CachedExpressionCompiler.Evaluate.
Expression<Func<object?, object?>> lambdaExpression =
Expression.Lambda<Func<object?, object?>>(
Expression.Convert(expression, typeof(object)),
UnusedParameterExpression);
var converted = Expression.Convert(expression, typeof(object));
var fakeParameter = Expression.Parameter(typeof(object), null);
var lambda = Expression.Lambda<Func<object?, object?>>(
converted,
fakeParameter);
var func = lambda.Compile();

var func = lambdaExpression.Compile();
return func(null);
}
}
Expand Down

0 comments on commit aede87c

Please sign in to comment.