diff --git a/Refit/RequestBuilderImplementation.cs b/Refit/RequestBuilderImplementation.cs index c24422b61..f580aa482 100644 --- a/Refit/RequestBuilderImplementation.cs +++ b/Refit/RequestBuilderImplementation.cs @@ -1067,12 +1067,12 @@ void AddPropertiesToRequest(RestMethodInfoInternal restMethod, HttpRequestMessag new HttpRequestOptionsKey( HttpRequestMessageOptions.RestMethodInfo ), - restMethod.ToRestMethodInfo() + restMethod.RestMethodInfo ); #else ret.Properties[HttpRequestMessageOptions.InterfaceType] = TargetType; ret.Properties[HttpRequestMessageOptions.RestMethodInfo] = - restMethod.ToRestMethodInfo(); + restMethod.RestMethodInfo; #endif } diff --git a/Refit/RestMethodInfo.cs b/Refit/RestMethodInfo.cs index 539f23a73..f7e758dbd 100644 --- a/Refit/RestMethodInfo.cs +++ b/Refit/RestMethodInfo.cs @@ -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 Headers { get; set; } - public Dictionary HeaderParameterMap { get; set; } - public Dictionary PropertyParameterMap { get; set; } - public Tuple? BodyParameterInfo { get; set; } - public Tuple? AuthorizeParameterInfo { get; set; } - public Dictionary QueryParameterMap { get; set; } - public Dictionary> AttachmentNameMap { get; set; } - public ParameterInfo[] ParameterInfoArray { get; set; } - public Dictionary ParameterMap { get; set; } + public RestMethodInfo RestMethodInfo { get; } + public ParameterInfo? CancellationToken { get; } + public UriFormat QueryUriFormat { get; } + public Dictionary Headers { get; } + public Dictionary HeaderParameterMap { get; } + public Dictionary PropertyParameterMap { get; } + public Tuple? BodyParameterInfo { get; } + public Tuple? AuthorizeParameterInfo { get; } + public Dictionary QueryParameterMap { get; } + public Dictionary> AttachmentNameMap { get; } + public ParameterInfo[] ParameterInfoArray { get; } + public Dictionary ParameterMap { get; } public List 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; } @@ -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().First(); @@ -97,7 +97,7 @@ public RestMethodInfoInternal( Headers = ParseHeaders(methodInfo); HeaderParameterMap = BuildHeaderParameterMap(ParameterInfoArray); - HeaderCollectionParameterIndex = RestMethodInfoInternal.GetHeaderCollectionParameterIndex( + HeaderCollectionParameterIndex = GetHeaderCollectionParameterIndex( ParameterInfoArray ); PropertyParameterMap = BuildRequestPropertyMap(ParameterInfoArray); @@ -164,6 +164,7 @@ public RestMethodInfoInternal( ); } + RestMethodInfo = new RestMethodInfo(Name, Type, MethodInfo, RelativePath, ReturnType!); CancellationToken = ctParam; QueryUriFormat = methodInfo.GetCustomAttribute()?.UriFormat @@ -216,9 +217,6 @@ static int GetHeaderCollectionParameterIndex(ParameterInfo[] parameterArray) return headerIndex; } - public RestMethodInfo ToRestMethodInfo() => - new(Name, Type, MethodInfo, RelativePath, ReturnType); - static Dictionary BuildRequestPropertyMap(ParameterInfo[] parameterArray) { Dictionary? propertyMap = null;