Skip to content

Commit

Permalink
rename variables, fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusz96 committed Dec 15, 2023
1 parent be6acb6 commit 9091b64
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/UriGeneration/Internal/ValuesExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ internal class ValuesExtractor : IValuesExtractor

private static readonly ParameterExpression FakeParameter =
Expression.Parameter(typeof(object), null);

private static readonly MemoryCacheEntryOptions CacheEntryOptions =
new() { Size = 1 };

Expand Down Expand Up @@ -85,19 +84,17 @@ public bool TryExtractValues<TController>(
{
_logger.ValidCacheEntryRetrieved(entry.ActionDescriptor);

var entryActionDescriptor = entry.ActionDescriptor;

var entryRouteValues = ExtractRouteValues(
entryActionDescriptor,
entry.ActionDescriptor,
methodCall.Arguments,
options);

_logger.ValuesExtracted();

values = new Values(
entryActionDescriptor.ActionName,
entryActionDescriptor.ControllerName,
entry.ActionDescriptor.ActionName,
entry.ActionDescriptor.ControllerName,
entryRouteValues);

_logger.ValuesExtracted();
return true;
}
else
Expand All @@ -108,7 +105,7 @@ public bool TryExtractValues<TController>(
}

if (!ValidateMethodConcreteness(method, controller)
|| !TryExtractActionDescriptor(method, actionDescriptors, out var actionDescriptor))
|| !TryExtractActionDescriptor(method, actionDescriptors, out var descriptor))
{
if (options?.BypassMethodCache is not true)
{
Expand All @@ -120,29 +117,29 @@ public bool TryExtractValues<TController>(
}

var routeValues = ExtractRouteValues(
actionDescriptor,
descriptor,
methodCall.Arguments,
options);

if (options?.BypassMethodCache is not true)
{
var validEntry = MethodCacheEntry.Valid(actionDescriptor);
var validEntry = MethodCacheEntry.Valid(descriptor);
methodCache.Set(key, validEntry, CacheEntryOptions);
}

_logger.ValuesExtracted();

values = new Values(
actionDescriptor.ActionName,
actionDescriptor.ControllerName,
descriptor.ActionName,
descriptor.ControllerName,
routeValues);

_logger.ValuesExtracted();
return true;
}
catch (Exception exception)
{
_logger.ValuesNotExtracted(expression, exception);

values = default;

_logger.ValuesNotExtracted(expression, exception);
return false;
}
}
Expand All @@ -166,6 +163,7 @@ private bool TryExtractMethodCall(
private MethodInfo ExtractMethod(MethodCallExpression methodCall)
{
var method = methodCall.Method;

_logger.MethodExtracted();
return method;
}
Expand All @@ -174,6 +172,7 @@ private Type ExtractController<TController>()
where TController : class
{
var controller = typeof(TController);

_logger.ControllerExtracted();
return controller;
}
Expand Down Expand Up @@ -229,35 +228,36 @@ private bool TryExtractActionDescriptor(
{
var bindingSource = parameter.BindingInfo?.BindingSource;

if (bindingSource is not null // Might be null in apps that don't use InferParameterBindingInfoConvention.
&& !bindingSource.CanAcceptDataFrom(BindingSource.Query)
&& !bindingSource.CanAcceptDataFrom(BindingSource.Path))
if (bindingSource is null // Might be null in apps that don't use InferParameterBindingInfoConvention.
|| bindingSource.CanAcceptDataFrom(BindingSource.Query)
|| bindingSource.CanAcceptDataFrom(BindingSource.Path))
{
_logger.BindingSource(bindingSource?.Id);
continue;
}
string key = parameter.Name;
var methodCallArgument = methodCallArguments[
parameter.ParameterInfo.Position];

string key = parameter.Name;
object? value;

var methodCallArgument = methodCallArguments[
parameter.ParameterInfo.Position];

object? value;
if (methodCallArgument is ConstantExpression ce)
{
value = ce.Value;
}
else
{
value = EvaluateExpression(methodCallArgument, options);
}

if (methodCallArgument is ConstantExpression ce)
{
value = ce.Value;
routeValues.Add(new KeyValuePair<string, object?>(key, value));
_logger.RouteValueExtracted(key, value);
}
else
{
value = EvaluateExpression(methodCallArgument, options);
_logger.BindingSource(bindingSource?.Id);
}

routeValues.Add(new KeyValuePair<string, object?>(key, value));
_logger.RouteValueExtracted(key, value);
}

string areaName = ExtractAreaName(actionDescriptor);

routeValues.Add(new KeyValuePair<string, object?>(AreaKey, areaName));
_logger.RouteValueExtracted(AreaKey, areaName);

Expand Down

0 comments on commit 9091b64

Please sign in to comment.