Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cache RestMethodInfo #1903

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Refit/RequestBuilderImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,12 +1068,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;
#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
Loading