Skip to content

Commit

Permalink
feat: cache RestMethodInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Nov 3, 2024
1 parent fa3a57b commit 73b3ece
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Refit/RequestBuilderImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,12 +1067,12 @@ void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessag
new HttpRequestOptionsKey<RestMethodInfo>(
HttpRequestMessageOptions.RestMethodInfo
),
restMethod.ToRestMethodInfo()
restMethod.RestMethodInfo
);
#else
ret.Properties[HttpRequestMessageOptions.InterfaceType] = TargetType;
ret.Properties[HttpRequestMessageOptions.RestMethodInfo] =
restMethod.ToRestMethodInfo();
restMethod.RestMethodInfo;

Check warning on line 1075 in Refit/RequestBuilderImplementation.cs

View check run for this annotation

Codecov / codecov/patch

Refit/RequestBuilderImplementation.cs#L1075

Added line #L1075 was not covered by tests
#endif
}

Expand Down
46 changes: 22 additions & 24 deletions Refit/RestMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,31 @@ Type ReturnType
[DebuggerDisplay("{MethodInfo}")]
internal class RestMethodInfoInternal
{
private int HeaderCollectionParameterIndex { get; set; }
public string Name { get; set; }
public Type Type { get; set; }
public MethodInfo MethodInfo { get; set; }
public HttpMethod HttpMethod { get; set; }
public string RelativePath { get; set; }
public bool IsMultipart { get; private set; }
private int HeaderCollectionParameterIndex { get; }
private string Name => MethodInfo.Name;
public Type Type { get; }
public MethodInfo MethodInfo { get; }
public HttpMethod HttpMethod { get; }
public string RelativePath { get; }
public bool IsMultipart { get; }
public string MultipartBoundary { get; private set; }
public ParameterInfo? CancellationToken { get; set; }
public UriFormat QueryUriFormat { get; set; }
public Dictionary<string, string?> Headers { get; set; }
public Dictionary<int, string> HeaderParameterMap { get; set; }
public Dictionary<int, string> PropertyParameterMap { get; set; }
public Tuple<BodySerializationMethod, bool, int>? BodyParameterInfo { get; set; }
public Tuple<string, int>? AuthorizeParameterInfo { get; set; }
public Dictionary<int, string> QueryParameterMap { get; set; }
public Dictionary<int, Tuple<string, string>> AttachmentNameMap { get; set; }
public ParameterInfo[] ParameterInfoArray { get; set; }
public Dictionary<int, RestMethodParameterInfo> ParameterMap { get; set; }
public RestMethodInfo RestMethodInfo { get; }
public ParameterInfo? CancellationToken { get; }
public UriFormat QueryUriFormat { get; }
public Dictionary<string, string?> Headers { get; }
public Dictionary<int, string> HeaderParameterMap { get; }
public Dictionary<int, string> PropertyParameterMap { get; }
public Tuple<BodySerializationMethod, bool, int>? BodyParameterInfo { get; }
public Tuple<string, int>? AuthorizeParameterInfo { get; }
public Dictionary<int, string> QueryParameterMap { get; }
public Dictionary<int, Tuple<string, string>> AttachmentNameMap { get; }
public ParameterInfo[] ParameterInfoArray { get; }
public Dictionary<int, RestMethodParameterInfo> ParameterMap { get; }
public List<ParameterFragment> FragmentPath { get ; set ; }
public Type ReturnType { get; set; }
public Type ReturnResultType { get; set; }
public Type DeserializedResultType { get; set; }
public RefitSettings RefitSettings { get; set; }
public RefitSettings RefitSettings { get; }
public bool IsApiResponse { get; }
public bool ShouldDisposeResponse { get; private set; }

Expand All @@ -67,7 +68,6 @@ public RestMethodInfoInternal(
{
RefitSettings = refitSettings ?? new RefitSettings();
Type = targetInterface ?? throw new ArgumentNullException(nameof(targetInterface));
Name = methodInfo.Name;
MethodInfo = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo));

var hma = methodInfo.GetCustomAttributes(true).OfType<HttpMethodAttribute>().First();
Expand Down Expand Up @@ -97,7 +97,7 @@ public RestMethodInfoInternal(

Headers = ParseHeaders(methodInfo);
HeaderParameterMap = BuildHeaderParameterMap(ParameterInfoArray);
HeaderCollectionParameterIndex = RestMethodInfoInternal.GetHeaderCollectionParameterIndex(
HeaderCollectionParameterIndex = GetHeaderCollectionParameterIndex(
ParameterInfoArray
);
PropertyParameterMap = BuildRequestPropertyMap(ParameterInfoArray);
Expand Down Expand Up @@ -164,6 +164,7 @@ public RestMethodInfoInternal(
);
}

RestMethodInfo = new RestMethodInfo(Name, Type, MethodInfo, RelativePath, ReturnType!);
CancellationToken = ctParam;

QueryUriFormat = methodInfo.GetCustomAttribute<QueryUriFormatAttribute>()?.UriFormat
Expand Down Expand Up @@ -216,9 +217,6 @@ static int GetHeaderCollectionParameterIndex(ParameterInfo[] parameterArray)
return headerIndex;
}

public RestMethodInfo ToRestMethodInfo() =>
new(Name, Type, MethodInfo, RelativePath, ReturnType);

static Dictionary<int, string> BuildRequestPropertyMap(ParameterInfo[] parameterArray)
{
Dictionary<int, string>? propertyMap = null;
Expand Down

0 comments on commit 73b3ece

Please sign in to comment.