Skip to content

Commit f5b1690

Browse files
feat: remove propertiesToAdd (#1741)
1 parent 44314ba commit f5b1690

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Refit/RequestBuilderImplementation.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RequestBuilderImplementation<TApi>(RefitSettings? refitSettings = null)
1515
partial class RequestBuilderImplementation : IRequestBuilder
1616
{
1717
static readonly QueryAttribute DefaultQueryAttribute = new ();
18-
static readonly Uri BaseUri = new Uri("http://api");
18+
static readonly Uri BaseUri = new ("http://api");
1919
readonly Dictionary<string, List<RestMethodInfoInternal>> interfaceHttpMethods;
2020
readonly ConcurrentDictionary<
2121
CloseGenericMethodKey,
@@ -641,7 +641,6 @@ bool paramsContainsCancellationToken
641641
(basePath == "/" ? string.Empty : basePath) + restMethod.RelativePath;
642642
var queryParamsToAdd = new List<KeyValuePair<string, string?>>();
643643
var headersToAdd = new Dictionary<string, string?>(restMethod.Headers);
644-
var propertiesToAdd = new Dictionary<string, object?>();
645644

646645
RestMethodParameterInfo? parameterInfo = null;
647646

@@ -764,9 +763,8 @@ bool paramsContainsCancellationToken
764763
}
765764

766765
//if property, add to populate into HttpRequestMessage.Properties
767-
if (restMethod.PropertyParameterMap.TryGetValue(i, out var propertyParameter))
766+
if (restMethod.PropertyParameterMap.ContainsKey(i))
768767
{
769-
propertiesToAdd[propertyParameter] = param;
770768
isParameterMappedToRequest = true;
771769
}
772770

@@ -797,7 +795,7 @@ bool paramsContainsCancellationToken
797795

798796
AddHeadersToRequest(headersToAdd, ret);
799797

800-
AddPropertiesToRequest(restMethod, ret, propertiesToAdd);
798+
AddPropertiesToRequest(restMethod, ret, paramList);
801799

802800
// NB: The URI methods in .NET are dumb. Also, we do this
803801
// UriBuilder business so that we preserve any hardcoded query
@@ -980,8 +978,7 @@ static void AddHeadersToRequest(Dictionary<string, string?> headersToAdd, HttpRe
980978
}
981979
}
982980

983-
void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessage ret,
984-
Dictionary<string, object?> propertiesToAdd)
981+
void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessage ret, object[] paramList)
985982
{
986983
// Add RefitSetting.HttpRequestMessageOptions to the HttpRequestMessage
987984
if (settings.HttpRequestMessageOptions != null)
@@ -996,16 +993,19 @@ void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessag
996993
}
997994
}
998995

999-
foreach (var property in propertiesToAdd)
996+
for (var i = 0; i < paramList.Length; i++)
1000997
{
998+
if (restMethod.PropertyParameterMap.TryGetValue(i, out var propertyKey))
999+
{
10011000
#if NET6_0_OR_GREATER
10021001
ret.Options.Set(
1003-
new HttpRequestOptionsKey<object?>(property.Key),
1004-
property.Value
1002+
new HttpRequestOptionsKey<object?>(propertyKey),
1003+
paramList[i]
10051004
);
10061005
#else
1007-
ret.Properties[property.Key] = property.Value;
1006+
ret.Properties[propertyKey] = paramList[i];
10081007
#endif
1008+
}
10091009
}
10101010

10111011
// Always add the top-level type of the interface to the properties

0 commit comments

Comments
 (0)