Fixes #82
This commit is contained in:
windischb 2018-01-27 22:50:46 +01:00 коммит произвёл Oren Novotny
Родитель fb8aafa45a
Коммит 2a048ddea7
13 изменённых файлов: 550 добавлений и 257 удалений

Просмотреть файл

@ -90,25 +90,6 @@ namespace Refit.Generator
public string MethodName { get; }
}
public class MultipleRefitMethodSameNameWarning : Warning
{
public MultipleRefitMethodSameNameWarning(InterfaceDeclarationSyntax @interface, MethodDeclarationSyntax method)
: base("RF002")
{
setLocation(method.GetLocation());
InterfaceName = @interface.Identifier.Text;
MethodName = method.Identifier.Text;
Message = string.Format(
"Method {0}.{1} has been declared multiple times. Refit doesn't support overloading.",
InterfaceName,
MethodName);
}
public string InterfaceName { get; }
public string MethodName { get; }
}
public class ReadOnlyFileError : Error
{

Просмотреть файл

@ -44,12 +44,16 @@ namespace {{Namespace}}
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGenerated{{GeneratedClassSuffix}}(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
{{#MethodList}}
{{#IsRefitMethod}}
methodImpls.Add("{{Name}}({{ArgumentListWithTypes}})", requestBuilder.BuildRestResultFuncForMethod("{{Name}}", new Type[] { {{ArgumentTypesList}} }));
{{/IsRefitMethod}}
{{/MethodList}}
}
{{#MethodList}}
@ -58,7 +62,7 @@ namespace {{Namespace}}
{
{{#IsRefitMethod}}
var arguments = new object[] { {{ArgumentList}} };
return ({{ReturnType}}) methodImpls["{{Name}}"](Client, arguments);
return ({{ReturnType}}) methodImpls["{{Name}}({{ArgumentListWithTypes}})"](Client, arguments);
{{/IsRefitMethod}}
{{^IsRefitMethod}}
throw new NotImplementedException("Either this method has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument.");

Просмотреть файл

@ -80,7 +80,7 @@ namespace Refit.Generator
var ns = parent as NamespaceDeclarationSyntax;
ret.Namespace = ns.Name.ToString();
ret.InterfaceName = getInterfaceName(interfaceTree.Identifier);
ret.InterfaceName = GetInterfaceName(interfaceTree.Identifier);
ret.GeneratedClassSuffix = ret.InterfaceName.Replace(".", "");
ret.Modifiers = interfaceTree.Modifiers.Select(t => t.ValueText).FirstOrDefault(m => m == "public" || m == "internal");
@ -107,6 +107,8 @@ namespace Refit.Generator
ArgumentListWithTypes = string.Join(",",
x.ParameterList.Parameters
.Select(y => $"{y.Type.ToString()} {y.Identifier.Text}")),
ArgumentTypesList = string.Join(",", x.ParameterList.Parameters
.Select(y => $"typeof({y.Type.ToString()})")),
IsRefitMethod = HasRefitHttpMethodAttribute(x)
})
.ToList();
@ -165,22 +167,8 @@ namespace Refit.Generator
.Where(x => !HasRefitHttpMethodAttribute(x.Method))
.Select(x => new MissingRefitAttributeWarning(x.Interface, x.Method));
var overloadWarnings = interfacesToGenerate
.SelectMany(i => i.Members.OfType<MethodDeclarationSyntax>().Select(m => new
{
Interface = i,
Method = m
}))
.Where(x => HasRefitHttpMethodAttribute(x.Method))
.GroupBy(x => new
{
x.Interface,
MethodName = x.Method.Identifier.Text
})
.Where(g => g.Count() > 1)
.SelectMany(g => g.Select(x => new MultipleRefitMethodSameNameWarning(x.Interface, x.Method)));
var diagnostics = missingAttributeWarnings.Concat<Diagnostic>(overloadWarnings);
var diagnostics = missingAttributeWarnings;
foreach (var diagnostic in diagnostics)
{
@ -199,7 +187,7 @@ namespace Refit.Generator
a.ArgumentList.Arguments[0].Expression.Kind() == SyntaxKind.StringLiteralExpression);
}
private string getInterfaceName(SyntaxToken identifier)
private string GetInterfaceName(SyntaxToken identifier)
{
if (identifier == null) return "";
var interfaceParent = identifier.Parent != null ? identifier.Parent.Parent : identifier.Parent;
@ -234,6 +222,7 @@ namespace Refit.Generator
{
public string ArgumentList { get; set; }
public string ArgumentListWithTypes { get; set; }
public string ArgumentTypesList { get; set; }
public bool IsRefitMethod { get; set; }
public string Name { get; set; }
public string ReturnType { get; set; }

Просмотреть файл

@ -1,16 +1,110 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Refit;
using RichardSzalay.MockHttp;
using Xunit;
namespace Refit.Tests
{
public interface IUseOverloadedMethods
{
[Get("/")]
Task Get();
[Get("")]
Task<string> Get();
[Get("/{id}")]
Task Get(int id);
[Get("/status/{httpstatuscode}")]
Task<HttpResponseMessage> Get(int httpstatuscode);
}
public interface IUseOverloadedGenericMethods<TResponse, in TParam, in THeader>
where TResponse : class
where THeader : struct
{
[Get("")]
Task<string> Get();
[Get("/get")]
Task<TResponse> Get(TParam param, [Header("X-Refit")] THeader header);
[Get("/get")]
Task<TResponse> Get(THeader param, [Header("X-Refit")] TParam header);
[Get("/status/{httpstatuscode}")]
Task<HttpResponseMessage> Get(int httpstatuscode);
}
public class MethodOverladTests
{
[Fact]
public async Task BasicMethodOverloadTest()
{
var mockHttp = new MockHttpMessageHandler();
var settings = new RefitSettings
{
HttpMessageHandlerFactory = () => mockHttp
};
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/")
.Respond(HttpStatusCode.OK, "text/html", "OK");
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/status/403")
.Respond(HttpStatusCode.Forbidden);
var fixture = RestService.For<IUseOverloadedMethods>("https://httpbin.org/", settings);
var plainText = await fixture.Get();
var resp = await fixture.Get(403);
Assert.True(!String.IsNullOrWhiteSpace(plainText));
Assert.Equal(HttpStatusCode.Forbidden, resp.StatusCode);
}
[Fact]
public async Task GenericMethodOverloadTest()
{
var mockHttp = new MockHttpMessageHandler();
var settings = new RefitSettings
{
HttpMessageHandlerFactory = () => mockHttp
};
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/")
.Respond(HttpStatusCode.OK, "text/html", "OK");
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/status/403")
.Respond(HttpStatusCode.Forbidden);
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/get")
.WithHeaders("X-Refit", "99")
.WithQueryString("param","foo")
.Respond("application/json", "{'url': 'https://httpbin.org/get', 'args': {'param': 'foo'}}");
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/get")
.WithHeaders("X-Refit", "foo")
.WithQueryString("param", "99")
.Respond("application/json", "{'url': 'https://httpbin.org/get', 'args': {'param': '99'}}");
var fixture = RestService.For<IUseOverloadedGenericMethods<HttpBinGet, string, int>>("https://httpbin.org/", settings);
var plainText = await fixture.Get();
var resp = await fixture.Get(403);
var result = await fixture.Get("foo", 99);
var result2 = await fixture.Get(99, "foo");
Assert.True(!String.IsNullOrWhiteSpace(plainText));
Assert.Equal(HttpStatusCode.Forbidden, resp.StatusCode);
Assert.Equal("foo", result.Args["param"]);
Assert.Equal("99", result2.Args["param"]);
}
}
}

Просмотреть файл

@ -40,7 +40,7 @@
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<RefitExecCmd>mono "$(MSBuildThisFileDirectory)../InterfaceStubGenerator.App/bin/$(Configuration)/net46/InterfaceStubGenerator.App.exe" "$(OutputStubsFile)" "$(MSBuildProjectDirectory)" "$(RefitParameterFile)"</RefitExecCmd>
</PropertyGroup>
<Message Text="Executing: $(RefitExecCmd)" />
<Message Text="Executing: $(RefitExecCmd)" Importance="High" />
<Exec Command="$(RefitExecCmd)" />
<Message Text="Processed Refit Stubs" />
</Target>
@ -58,7 +58,7 @@
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<RefitExecCmd>dotnet "$(MSBuildThisFileDirectory)../InterfaceStubGenerator.App/bin/$(Configuration)/netcoreapp2.0/InterfaceStubGenerator.App.dll" "$(OutputStubsFile)" "$(MSBuildProjectDirectory)" "$(RefitParameterFile)"</RefitExecCmd>
</PropertyGroup>
<Message Text="Executing: $(RefitExecCmd)" />
<Message Text="Executing: $(RefitExecCmd)" Importance="High" />
<Exec Command="$(RefitExecCmd)" />
<Message Text="Processed Refit Stubs" />
</Target>

Просмотреть файл

@ -58,26 +58,29 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIAmARefitInterfaceButNobodyUsesMe(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("RefitMethod()", requestBuilder.BuildRestResultFuncForMethod("RefitMethod", new Type[] { }));
methodImpls.Add("AnotherRefitMethod()", requestBuilder.BuildRestResultFuncForMethod("AnotherRefitMethod", new Type[] { }));
methodImpls.Add("SpacesShouldntBreakMe()", requestBuilder.BuildRestResultFuncForMethod("SpacesShouldntBreakMe", new Type[] { }));
methodImpls.Add("ReservedWordsForParameterNames(int @int,string @string,float @long)", requestBuilder.BuildRestResultFuncForMethod("ReservedWordsForParameterNames", new Type[] { typeof(int),typeof(string),typeof(float) }));
}
/// <inheritdoc />
public virtual Task RefitMethod()
{
var arguments = new object[] { };
return (Task) methodImpls["RefitMethod"](Client, arguments);
return (Task) methodImpls["RefitMethod()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task AnotherRefitMethod()
{
var arguments = new object[] { };
return (Task) methodImpls["AnotherRefitMethod"](Client, arguments);
return (Task) methodImpls["AnotherRefitMethod()"](Client, arguments);
}
/// <inheritdoc />
@ -90,14 +93,14 @@ namespace Refit.Tests
public virtual Task SpacesShouldntBreakMe()
{
var arguments = new object[] { };
return (Task) methodImpls["SpacesShouldntBreakMe"](Client, arguments);
return (Task) methodImpls["SpacesShouldntBreakMe()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task ReservedWordsForParameterNames(int @int,string @string,float @long)
{
var arguments = new object[] { @int,@string,@long };
return (Task) methodImpls["ReservedWordsForParameterNames"](Client, arguments);
return (Task) methodImpls["ReservedWordsForParameterNames(int @int,string @string,float @long)"](Client, arguments);
}
}
@ -113,19 +116,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIAmHalfRefit(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Post()", requestBuilder.BuildRestResultFuncForMethod("Post", new Type[] { }));
}
/// <inheritdoc />
public virtual Task Post()
{
var arguments = new object[] { };
return (Task) methodImpls["Post"](Client, arguments);
return (Task) methodImpls["Post()"](Client, arguments);
}
/// <inheritdoc />
@ -148,47 +151,51 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIBoringCrudApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Create(T paylod)", requestBuilder.BuildRestResultFuncForMethod("Create", new Type[] { typeof(T) }));
methodImpls.Add("ReadAll()", requestBuilder.BuildRestResultFuncForMethod("ReadAll", new Type[] { }));
methodImpls.Add("ReadOne(TKey key)", requestBuilder.BuildRestResultFuncForMethod("ReadOne", new Type[] { typeof(TKey) }));
methodImpls.Add("Update(TKey key,T payload)", requestBuilder.BuildRestResultFuncForMethod("Update", new Type[] { typeof(TKey),typeof(T) }));
methodImpls.Add("Delete(TKey key)", requestBuilder.BuildRestResultFuncForMethod("Delete", new Type[] { typeof(TKey) }));
}
/// <inheritdoc />
public virtual Task<T> Create(T paylod)
{
var arguments = new object[] { paylod };
return (Task<T>) methodImpls["Create"](Client, arguments);
return (Task<T>) methodImpls["Create(T paylod)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<List<T>> ReadAll()
{
var arguments = new object[] { };
return (Task<List<T>>) methodImpls["ReadAll"](Client, arguments);
return (Task<List<T>>) methodImpls["ReadAll()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<T> ReadOne(TKey key)
{
var arguments = new object[] { key };
return (Task<T>) methodImpls["ReadOne"](Client, arguments);
return (Task<T>) methodImpls["ReadOne(TKey key)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task Update(TKey key,T payload)
{
var arguments = new object[] { key,payload };
return (Task) methodImpls["Update"](Client, arguments);
return (Task) methodImpls["Update(TKey key,T payload)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task Delete(TKey key)
{
var arguments = new object[] { key };
return (Task) methodImpls["Delete"](Client, arguments);
return (Task) methodImpls["Delete(TKey key)"](Client, arguments);
}
}
@ -204,19 +211,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIBrokenWebApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("PostAValue(string derp)", requestBuilder.BuildRestResultFuncForMethod("PostAValue", new Type[] { typeof(string) }));
}
/// <inheritdoc />
public virtual Task<bool> PostAValue(string derp)
{
var arguments = new object[] { derp };
return (Task<bool>) methodImpls["PostAValue"](Client, arguments);
return (Task<bool>) methodImpls["PostAValue(string derp)"](Client, arguments);
}
}
@ -232,68 +239,75 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIGitHubApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("GetUser(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUser", new Type[] { typeof(string) }));
methodImpls.Add("GetUserObservable(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", new Type[] { typeof(string) }));
methodImpls.Add("GetUserCamelCase(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", new Type[] { typeof(string) }));
methodImpls.Add("GetOrgMembers(string orgName)", requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", new Type[] { typeof(string) }));
methodImpls.Add("FindUsers(string q)", requestBuilder.BuildRestResultFuncForMethod("FindUsers", new Type[] { typeof(string) }));
methodImpls.Add("GetIndex()", requestBuilder.BuildRestResultFuncForMethod("GetIndex", new Type[] { }));
methodImpls.Add("GetIndexObservable()", requestBuilder.BuildRestResultFuncForMethod("GetIndexObservable", new Type[] { }));
methodImpls.Add("NothingToSeeHere()", requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHere", new Type[] { }));
}
/// <inheritdoc />
public virtual Task<User> GetUser(string userName)
{
var arguments = new object[] { userName };
return (Task<User>) methodImpls["GetUser"](Client, arguments);
return (Task<User>) methodImpls["GetUser(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<User> GetUserObservable(string userName)
{
var arguments = new object[] { userName };
return (IObservable<User>) methodImpls["GetUserObservable"](Client, arguments);
return (IObservable<User>) methodImpls["GetUserObservable(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<User> GetUserCamelCase(string userName)
{
var arguments = new object[] { userName };
return (IObservable<User>) methodImpls["GetUserCamelCase"](Client, arguments);
return (IObservable<User>) methodImpls["GetUserCamelCase(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<List<User>> GetOrgMembers(string orgName)
{
var arguments = new object[] { orgName };
return (Task<List<User>>) methodImpls["GetOrgMembers"](Client, arguments);
return (Task<List<User>>) methodImpls["GetOrgMembers(string orgName)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<UserSearchResult> FindUsers(string q)
{
var arguments = new object[] { q };
return (Task<UserSearchResult>) methodImpls["FindUsers"](Client, arguments);
return (Task<UserSearchResult>) methodImpls["FindUsers(string q)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> GetIndex()
{
var arguments = new object[] { };
return (Task<HttpResponseMessage>) methodImpls["GetIndex"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["GetIndex()"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<string> GetIndexObservable()
{
var arguments = new object[] { };
return (IObservable<string>) methodImpls["GetIndexObservable"](Client, arguments);
return (IObservable<string>) methodImpls["GetIndexObservable()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task NothingToSeeHere()
{
var arguments = new object[] { };
return (Task) methodImpls["NothingToSeeHere"](Client, arguments);
return (Task) methodImpls["NothingToSeeHere()"](Client, arguments);
}
}
@ -311,33 +325,35 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIHttpBinApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Get(TParam param,THeader header)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(TParam),typeof(THeader) }));
methodImpls.Add("GetQuery(TParam param)", requestBuilder.BuildRestResultFuncForMethod("GetQuery", new Type[] { typeof(TParam) }));
methodImpls.Add("GetQueryWithIncludeParameterName(TParam param)", requestBuilder.BuildRestResultFuncForMethod("GetQueryWithIncludeParameterName", new Type[] { typeof(TParam) }));
}
/// <inheritdoc />
public virtual Task<TResponse> Get(TParam param,THeader header)
{
var arguments = new object[] { param,header };
return (Task<TResponse>) methodImpls["Get"](Client, arguments);
return (Task<TResponse>) methodImpls["Get(TParam param,THeader header)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<TResponse> GetQuery(TParam param)
{
var arguments = new object[] { param };
return (Task<TResponse>) methodImpls["GetQuery"](Client, arguments);
return (Task<TResponse>) methodImpls["GetQuery(TParam param)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<TResponse> GetQueryWithIncludeParameterName(TParam param)
{
var arguments = new object[] { param };
return (Task<TResponse>) methodImpls["GetQueryWithIncludeParameterName"](Client, arguments);
return (Task<TResponse>) methodImpls["GetQueryWithIncludeParameterName(TParam param)"](Client, arguments);
}
}
@ -353,19 +369,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIHttpContentApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("PostFileUpload(HttpContent content)", requestBuilder.BuildRestResultFuncForMethod("PostFileUpload", new Type[] { typeof(HttpContent) }));
}
/// <inheritdoc />
public virtual Task<HttpContent> PostFileUpload(HttpContent content)
{
var arguments = new object[] { content };
return (Task<HttpContent>) methodImpls["PostFileUpload"](Client, arguments);
return (Task<HttpContent>) methodImpls["PostFileUpload(HttpContent content)"](Client, arguments);
}
}
@ -381,19 +397,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedINamespaceCollisionApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("SomeRequest()", requestBuilder.BuildRestResultFuncForMethod("SomeRequest", new Type[] { }));
}
/// <inheritdoc />
public virtual Task<SomeType> SomeRequest()
{
var arguments = new object[] { };
return (Task<SomeType>) methodImpls["SomeRequest"](Client, arguments);
return (Task<SomeType>) methodImpls["SomeRequest()"](Client, arguments);
}
}
@ -409,68 +425,75 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedTestNestedINestedGitHubApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("GetUser(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUser", new Type[] { typeof(string) }));
methodImpls.Add("GetUserObservable(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", new Type[] { typeof(string) }));
methodImpls.Add("GetUserCamelCase(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", new Type[] { typeof(string) }));
methodImpls.Add("GetOrgMembers(string orgName)", requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", new Type[] { typeof(string) }));
methodImpls.Add("FindUsers(string q)", requestBuilder.BuildRestResultFuncForMethod("FindUsers", new Type[] { typeof(string) }));
methodImpls.Add("GetIndex()", requestBuilder.BuildRestResultFuncForMethod("GetIndex", new Type[] { }));
methodImpls.Add("GetIndexObservable()", requestBuilder.BuildRestResultFuncForMethod("GetIndexObservable", new Type[] { }));
methodImpls.Add("NothingToSeeHere()", requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHere", new Type[] { }));
}
/// <inheritdoc />
public virtual Task<User> GetUser(string userName)
{
var arguments = new object[] { userName };
return (Task<User>) methodImpls["GetUser"](Client, arguments);
return (Task<User>) methodImpls["GetUser(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<User> GetUserObservable(string userName)
{
var arguments = new object[] { userName };
return (IObservable<User>) methodImpls["GetUserObservable"](Client, arguments);
return (IObservable<User>) methodImpls["GetUserObservable(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<User> GetUserCamelCase(string userName)
{
var arguments = new object[] { userName };
return (IObservable<User>) methodImpls["GetUserCamelCase"](Client, arguments);
return (IObservable<User>) methodImpls["GetUserCamelCase(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<List<User>> GetOrgMembers(string orgName)
{
var arguments = new object[] { orgName };
return (Task<List<User>>) methodImpls["GetOrgMembers"](Client, arguments);
return (Task<List<User>>) methodImpls["GetOrgMembers(string orgName)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<UserSearchResult> FindUsers(string q)
{
var arguments = new object[] { q };
return (Task<UserSearchResult>) methodImpls["FindUsers"](Client, arguments);
return (Task<UserSearchResult>) methodImpls["FindUsers(string q)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> GetIndex()
{
var arguments = new object[] { };
return (Task<HttpResponseMessage>) methodImpls["GetIndex"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["GetIndex()"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<string> GetIndexObservable()
{
var arguments = new object[] { };
return (IObservable<string>) methodImpls["GetIndexObservable"](Client, arguments);
return (IObservable<string>) methodImpls["GetIndexObservable()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task NothingToSeeHere()
{
var arguments = new object[] { };
return (Task) methodImpls["NothingToSeeHere"](Client, arguments);
return (Task) methodImpls["NothingToSeeHere()"](Client, arguments);
}
}
@ -486,19 +509,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedINpmJs(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("GetCongruence()", requestBuilder.BuildRestResultFuncForMethod("GetCongruence", new Type[] { }));
}
/// <inheritdoc />
public virtual Task<RootObject> GetCongruence()
{
var arguments = new object[] { };
return (Task<RootObject>) methodImpls["GetCongruence"](Client, arguments);
return (Task<RootObject>) methodImpls["GetCongruence()"](Client, arguments);
}
}
@ -514,19 +537,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIRequestBin(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Post()", requestBuilder.BuildRestResultFuncForMethod("Post", new Type[] { }));
}
/// <inheritdoc />
public virtual Task Post()
{
var arguments = new object[] { };
return (Task) methodImpls["Post"](Client, arguments);
return (Task) methodImpls["Post()"](Client, arguments);
}
}
@ -542,61 +565,67 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIRunscopeApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("UploadStream(Stream stream)", requestBuilder.BuildRestResultFuncForMethod("UploadStream", new Type[] { typeof(Stream) }));
methodImpls.Add("UploadStreamPart(StreamPart stream)", requestBuilder.BuildRestResultFuncForMethod("UploadStreamPart", new Type[] { typeof(StreamPart) }));
methodImpls.Add("UploadBytes(byte[] bytes)", requestBuilder.BuildRestResultFuncForMethod("UploadBytes", new Type[] { typeof(byte[]) }));
methodImpls.Add("UploadBytesPart(ByteArrayPart bytes)", requestBuilder.BuildRestResultFuncForMethod("UploadBytesPart", new Type[] { typeof(ByteArrayPart) }));
methodImpls.Add("UploadString(string someString)", requestBuilder.BuildRestResultFuncForMethod("UploadString", new Type[] { typeof(string) }));
methodImpls.Add("UploadFileInfo(IEnumerable<FileInfo> fileInfos,FileInfo anotherFile)", requestBuilder.BuildRestResultFuncForMethod("UploadFileInfo", new Type[] { typeof(IEnumerable<FileInfo>),typeof(FileInfo) }));
methodImpls.Add("UploadFileInfoPart(IEnumerable<FileInfoPart> fileInfos,FileInfoPart anotherFile)", requestBuilder.BuildRestResultFuncForMethod("UploadFileInfoPart", new Type[] { typeof(IEnumerable<FileInfoPart>),typeof(FileInfoPart) }));
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadStream(Stream stream)
{
var arguments = new object[] { stream };
return (Task<HttpResponseMessage>) methodImpls["UploadStream"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadStream(Stream stream)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadStreamPart(StreamPart stream)
{
var arguments = new object[] { stream };
return (Task<HttpResponseMessage>) methodImpls["UploadStreamPart"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadStreamPart(StreamPart stream)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadBytes(byte[] bytes)
{
var arguments = new object[] { bytes };
return (Task<HttpResponseMessage>) methodImpls["UploadBytes"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadBytes(byte[] bytes)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadBytesPart(ByteArrayPart bytes)
{
var arguments = new object[] { bytes };
return (Task<HttpResponseMessage>) methodImpls["UploadBytesPart"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadBytesPart(ByteArrayPart bytes)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadString(string someString)
{
var arguments = new object[] { someString };
return (Task<HttpResponseMessage>) methodImpls["UploadString"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadString(string someString)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadFileInfo(IEnumerable<FileInfo> fileInfos,FileInfo anotherFile)
{
var arguments = new object[] { fileInfos,anotherFile };
return (Task<HttpResponseMessage>) methodImpls["UploadFileInfo"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadFileInfo(IEnumerable<FileInfo> fileInfos,FileInfo anotherFile)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadFileInfoPart(IEnumerable<FileInfoPart> fileInfos,FileInfoPart anotherFile)
{
var arguments = new object[] { fileInfos,anotherFile };
return (Task<HttpResponseMessage>) methodImpls["UploadFileInfoPart"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadFileInfoPart(IEnumerable<FileInfoPart> fileInfos,FileInfoPart anotherFile)"](Client, arguments);
}
}
@ -612,19 +641,73 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIStreamApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("GetRemoteFile(string filename)", requestBuilder.BuildRestResultFuncForMethod("GetRemoteFile", new Type[] { typeof(string) }));
}
/// <inheritdoc />
public virtual Task<Stream> GetRemoteFile(string filename)
{
var arguments = new object[] { filename };
return (Task<Stream>) methodImpls["GetRemoteFile"](Client, arguments);
return (Task<Stream>) methodImpls["GetRemoteFile(string filename)"](Client, arguments);
}
}
}
namespace Refit.Tests
{
using RefitInternalGenerated;
/// <inheritdoc />
[Preserve]
public partial class AutoGeneratedIUseOverloadedGenericMethods<TResponse, TParam, THeader> : IUseOverloadedGenericMethods<TResponse, TParam, THeader>
where TResponse : class
where THeader : struct
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIUseOverloadedGenericMethods(HttpClient client, IRequestBuilder requestBuilder)
{
Client = client;
methodImpls.Add("Get()", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { }));
methodImpls.Add("Get(TParam param,THeader header)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(TParam),typeof(THeader) }));
methodImpls.Add("Get(THeader param,TParam header)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(THeader),typeof(TParam) }));
methodImpls.Add("Get(int httpstatuscode)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(int) }));
}
/// <inheritdoc />
public virtual Task<string> Get()
{
var arguments = new object[] { };
return (Task<string>) methodImpls["Get()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<TResponse> Get(TParam param,THeader header)
{
var arguments = new object[] { param,header };
return (Task<TResponse>) methodImpls["Get(TParam param,THeader header)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<TResponse> Get(THeader param,TParam header)
{
var arguments = new object[] { param,header };
return (Task<TResponse>) methodImpls["Get(THeader param,TParam header)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> Get(int httpstatuscode)
{
var arguments = new object[] { httpstatuscode };
return (Task<HttpResponseMessage>) methodImpls["Get(int httpstatuscode)"](Client, arguments);
}
}
@ -640,26 +723,27 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIUseOverloadedMethods(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Get()", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { }));
methodImpls.Add("Get(int httpstatuscode)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(int) }));
}
/// <inheritdoc />
public virtual Task Get()
public virtual Task<string> Get()
{
var arguments = new object[] { };
return (Task) methodImpls["Get"](Client, arguments);
return (Task<string>) methodImpls["Get()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task Get(int id)
public virtual Task<HttpResponseMessage> Get(int httpstatuscode)
{
var arguments = new object[] { id };
return (Task) methodImpls["Get"](Client, arguments);
var arguments = new object[] { httpstatuscode };
return (Task<HttpResponseMessage>) methodImpls["Get(int httpstatuscode)"](Client, arguments);
}
}

Просмотреть файл

@ -58,26 +58,29 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIAmARefitInterfaceButNobodyUsesMe(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("RefitMethod()", requestBuilder.BuildRestResultFuncForMethod("RefitMethod", new Type[] { }));
methodImpls.Add("AnotherRefitMethod()", requestBuilder.BuildRestResultFuncForMethod("AnotherRefitMethod", new Type[] { }));
methodImpls.Add("SpacesShouldntBreakMe()", requestBuilder.BuildRestResultFuncForMethod("SpacesShouldntBreakMe", new Type[] { }));
methodImpls.Add("ReservedWordsForParameterNames(int @int,string @string,float @long)", requestBuilder.BuildRestResultFuncForMethod("ReservedWordsForParameterNames", new Type[] { typeof(int),typeof(string),typeof(float) }));
}
/// <inheritdoc />
public virtual Task RefitMethod()
{
var arguments = new object[] { };
return (Task) methodImpls["RefitMethod"](Client, arguments);
return (Task) methodImpls["RefitMethod()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task AnotherRefitMethod()
{
var arguments = new object[] { };
return (Task) methodImpls["AnotherRefitMethod"](Client, arguments);
return (Task) methodImpls["AnotherRefitMethod()"](Client, arguments);
}
/// <inheritdoc />
@ -90,14 +93,14 @@ namespace Refit.Tests
public virtual Task SpacesShouldntBreakMe()
{
var arguments = new object[] { };
return (Task) methodImpls["SpacesShouldntBreakMe"](Client, arguments);
return (Task) methodImpls["SpacesShouldntBreakMe()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task ReservedWordsForParameterNames(int @int,string @string,float @long)
{
var arguments = new object[] { @int,@string,@long };
return (Task) methodImpls["ReservedWordsForParameterNames"](Client, arguments);
return (Task) methodImpls["ReservedWordsForParameterNames(int @int,string @string,float @long)"](Client, arguments);
}
}
@ -113,19 +116,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIAmHalfRefit(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Post()", requestBuilder.BuildRestResultFuncForMethod("Post", new Type[] { }));
}
/// <inheritdoc />
public virtual Task Post()
{
var arguments = new object[] { };
return (Task) methodImpls["Post"](Client, arguments);
return (Task) methodImpls["Post()"](Client, arguments);
}
/// <inheritdoc />
@ -148,47 +151,51 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIBoringCrudApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Create(T paylod)", requestBuilder.BuildRestResultFuncForMethod("Create", new Type[] { typeof(T) }));
methodImpls.Add("ReadAll()", requestBuilder.BuildRestResultFuncForMethod("ReadAll", new Type[] { }));
methodImpls.Add("ReadOne(TKey key)", requestBuilder.BuildRestResultFuncForMethod("ReadOne", new Type[] { typeof(TKey) }));
methodImpls.Add("Update(TKey key,T payload)", requestBuilder.BuildRestResultFuncForMethod("Update", new Type[] { typeof(TKey),typeof(T) }));
methodImpls.Add("Delete(TKey key)", requestBuilder.BuildRestResultFuncForMethod("Delete", new Type[] { typeof(TKey) }));
}
/// <inheritdoc />
public virtual Task<T> Create(T paylod)
{
var arguments = new object[] { paylod };
return (Task<T>) methodImpls["Create"](Client, arguments);
return (Task<T>) methodImpls["Create(T paylod)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<List<T>> ReadAll()
{
var arguments = new object[] { };
return (Task<List<T>>) methodImpls["ReadAll"](Client, arguments);
return (Task<List<T>>) methodImpls["ReadAll()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<T> ReadOne(TKey key)
{
var arguments = new object[] { key };
return (Task<T>) methodImpls["ReadOne"](Client, arguments);
return (Task<T>) methodImpls["ReadOne(TKey key)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task Update(TKey key,T payload)
{
var arguments = new object[] { key,payload };
return (Task) methodImpls["Update"](Client, arguments);
return (Task) methodImpls["Update(TKey key,T payload)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task Delete(TKey key)
{
var arguments = new object[] { key };
return (Task) methodImpls["Delete"](Client, arguments);
return (Task) methodImpls["Delete(TKey key)"](Client, arguments);
}
}
@ -204,19 +211,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIBrokenWebApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("PostAValue(string derp)", requestBuilder.BuildRestResultFuncForMethod("PostAValue", new Type[] { typeof(string) }));
}
/// <inheritdoc />
public virtual Task<bool> PostAValue(string derp)
{
var arguments = new object[] { derp };
return (Task<bool>) methodImpls["PostAValue"](Client, arguments);
return (Task<bool>) methodImpls["PostAValue(string derp)"](Client, arguments);
}
}
@ -232,68 +239,75 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIGitHubApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("GetUser(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUser", new Type[] { typeof(string) }));
methodImpls.Add("GetUserObservable(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", new Type[] { typeof(string) }));
methodImpls.Add("GetUserCamelCase(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", new Type[] { typeof(string) }));
methodImpls.Add("GetOrgMembers(string orgName)", requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", new Type[] { typeof(string) }));
methodImpls.Add("FindUsers(string q)", requestBuilder.BuildRestResultFuncForMethod("FindUsers", new Type[] { typeof(string) }));
methodImpls.Add("GetIndex()", requestBuilder.BuildRestResultFuncForMethod("GetIndex", new Type[] { }));
methodImpls.Add("GetIndexObservable()", requestBuilder.BuildRestResultFuncForMethod("GetIndexObservable", new Type[] { }));
methodImpls.Add("NothingToSeeHere()", requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHere", new Type[] { }));
}
/// <inheritdoc />
public virtual Task<User> GetUser(string userName)
{
var arguments = new object[] { userName };
return (Task<User>) methodImpls["GetUser"](Client, arguments);
return (Task<User>) methodImpls["GetUser(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<User> GetUserObservable(string userName)
{
var arguments = new object[] { userName };
return (IObservable<User>) methodImpls["GetUserObservable"](Client, arguments);
return (IObservable<User>) methodImpls["GetUserObservable(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<User> GetUserCamelCase(string userName)
{
var arguments = new object[] { userName };
return (IObservable<User>) methodImpls["GetUserCamelCase"](Client, arguments);
return (IObservable<User>) methodImpls["GetUserCamelCase(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<List<User>> GetOrgMembers(string orgName)
{
var arguments = new object[] { orgName };
return (Task<List<User>>) methodImpls["GetOrgMembers"](Client, arguments);
return (Task<List<User>>) methodImpls["GetOrgMembers(string orgName)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<UserSearchResult> FindUsers(string q)
{
var arguments = new object[] { q };
return (Task<UserSearchResult>) methodImpls["FindUsers"](Client, arguments);
return (Task<UserSearchResult>) methodImpls["FindUsers(string q)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> GetIndex()
{
var arguments = new object[] { };
return (Task<HttpResponseMessage>) methodImpls["GetIndex"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["GetIndex()"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<string> GetIndexObservable()
{
var arguments = new object[] { };
return (IObservable<string>) methodImpls["GetIndexObservable"](Client, arguments);
return (IObservable<string>) methodImpls["GetIndexObservable()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task NothingToSeeHere()
{
var arguments = new object[] { };
return (Task) methodImpls["NothingToSeeHere"](Client, arguments);
return (Task) methodImpls["NothingToSeeHere()"](Client, arguments);
}
}
@ -311,33 +325,35 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIHttpBinApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Get(TParam param,THeader header)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(TParam),typeof(THeader) }));
methodImpls.Add("GetQuery(TParam param)", requestBuilder.BuildRestResultFuncForMethod("GetQuery", new Type[] { typeof(TParam) }));
methodImpls.Add("GetQueryWithIncludeParameterName(TParam param)", requestBuilder.BuildRestResultFuncForMethod("GetQueryWithIncludeParameterName", new Type[] { typeof(TParam) }));
}
/// <inheritdoc />
public virtual Task<TResponse> Get(TParam param,THeader header)
{
var arguments = new object[] { param,header };
return (Task<TResponse>) methodImpls["Get"](Client, arguments);
return (Task<TResponse>) methodImpls["Get(TParam param,THeader header)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<TResponse> GetQuery(TParam param)
{
var arguments = new object[] { param };
return (Task<TResponse>) methodImpls["GetQuery"](Client, arguments);
return (Task<TResponse>) methodImpls["GetQuery(TParam param)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<TResponse> GetQueryWithIncludeParameterName(TParam param)
{
var arguments = new object[] { param };
return (Task<TResponse>) methodImpls["GetQueryWithIncludeParameterName"](Client, arguments);
return (Task<TResponse>) methodImpls["GetQueryWithIncludeParameterName(TParam param)"](Client, arguments);
}
}
@ -353,19 +369,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIHttpContentApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("PostFileUpload(HttpContent content)", requestBuilder.BuildRestResultFuncForMethod("PostFileUpload", new Type[] { typeof(HttpContent) }));
}
/// <inheritdoc />
public virtual Task<HttpContent> PostFileUpload(HttpContent content)
{
var arguments = new object[] { content };
return (Task<HttpContent>) methodImpls["PostFileUpload"](Client, arguments);
return (Task<HttpContent>) methodImpls["PostFileUpload(HttpContent content)"](Client, arguments);
}
}
@ -381,19 +397,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedINamespaceCollisionApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("SomeRequest()", requestBuilder.BuildRestResultFuncForMethod("SomeRequest", new Type[] { }));
}
/// <inheritdoc />
public virtual Task<SomeType> SomeRequest()
{
var arguments = new object[] { };
return (Task<SomeType>) methodImpls["SomeRequest"](Client, arguments);
return (Task<SomeType>) methodImpls["SomeRequest()"](Client, arguments);
}
}
@ -409,68 +425,75 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedTestNestedINestedGitHubApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("GetUser(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUser", new Type[] { typeof(string) }));
methodImpls.Add("GetUserObservable(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUserObservable", new Type[] { typeof(string) }));
methodImpls.Add("GetUserCamelCase(string userName)", requestBuilder.BuildRestResultFuncForMethod("GetUserCamelCase", new Type[] { typeof(string) }));
methodImpls.Add("GetOrgMembers(string orgName)", requestBuilder.BuildRestResultFuncForMethod("GetOrgMembers", new Type[] { typeof(string) }));
methodImpls.Add("FindUsers(string q)", requestBuilder.BuildRestResultFuncForMethod("FindUsers", new Type[] { typeof(string) }));
methodImpls.Add("GetIndex()", requestBuilder.BuildRestResultFuncForMethod("GetIndex", new Type[] { }));
methodImpls.Add("GetIndexObservable()", requestBuilder.BuildRestResultFuncForMethod("GetIndexObservable", new Type[] { }));
methodImpls.Add("NothingToSeeHere()", requestBuilder.BuildRestResultFuncForMethod("NothingToSeeHere", new Type[] { }));
}
/// <inheritdoc />
public virtual Task<User> GetUser(string userName)
{
var arguments = new object[] { userName };
return (Task<User>) methodImpls["GetUser"](Client, arguments);
return (Task<User>) methodImpls["GetUser(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<User> GetUserObservable(string userName)
{
var arguments = new object[] { userName };
return (IObservable<User>) methodImpls["GetUserObservable"](Client, arguments);
return (IObservable<User>) methodImpls["GetUserObservable(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<User> GetUserCamelCase(string userName)
{
var arguments = new object[] { userName };
return (IObservable<User>) methodImpls["GetUserCamelCase"](Client, arguments);
return (IObservable<User>) methodImpls["GetUserCamelCase(string userName)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<List<User>> GetOrgMembers(string orgName)
{
var arguments = new object[] { orgName };
return (Task<List<User>>) methodImpls["GetOrgMembers"](Client, arguments);
return (Task<List<User>>) methodImpls["GetOrgMembers(string orgName)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<UserSearchResult> FindUsers(string q)
{
var arguments = new object[] { q };
return (Task<UserSearchResult>) methodImpls["FindUsers"](Client, arguments);
return (Task<UserSearchResult>) methodImpls["FindUsers(string q)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> GetIndex()
{
var arguments = new object[] { };
return (Task<HttpResponseMessage>) methodImpls["GetIndex"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["GetIndex()"](Client, arguments);
}
/// <inheritdoc />
public virtual IObservable<string> GetIndexObservable()
{
var arguments = new object[] { };
return (IObservable<string>) methodImpls["GetIndexObservable"](Client, arguments);
return (IObservable<string>) methodImpls["GetIndexObservable()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task NothingToSeeHere()
{
var arguments = new object[] { };
return (Task) methodImpls["NothingToSeeHere"](Client, arguments);
return (Task) methodImpls["NothingToSeeHere()"](Client, arguments);
}
}
@ -486,19 +509,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedINpmJs(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("GetCongruence()", requestBuilder.BuildRestResultFuncForMethod("GetCongruence", new Type[] { }));
}
/// <inheritdoc />
public virtual Task<RootObject> GetCongruence()
{
var arguments = new object[] { };
return (Task<RootObject>) methodImpls["GetCongruence"](Client, arguments);
return (Task<RootObject>) methodImpls["GetCongruence()"](Client, arguments);
}
}
@ -514,19 +537,19 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIRequestBin(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Post()", requestBuilder.BuildRestResultFuncForMethod("Post", new Type[] { }));
}
/// <inheritdoc />
public virtual Task Post()
{
var arguments = new object[] { };
return (Task) methodImpls["Post"](Client, arguments);
return (Task) methodImpls["Post()"](Client, arguments);
}
}
@ -542,61 +565,67 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIRunscopeApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("UploadStream(Stream stream)", requestBuilder.BuildRestResultFuncForMethod("UploadStream", new Type[] { typeof(Stream) }));
methodImpls.Add("UploadStreamPart(StreamPart stream)", requestBuilder.BuildRestResultFuncForMethod("UploadStreamPart", new Type[] { typeof(StreamPart) }));
methodImpls.Add("UploadBytes(byte[] bytes)", requestBuilder.BuildRestResultFuncForMethod("UploadBytes", new Type[] { typeof(byte[]) }));
methodImpls.Add("UploadBytesPart(ByteArrayPart bytes)", requestBuilder.BuildRestResultFuncForMethod("UploadBytesPart", new Type[] { typeof(ByteArrayPart) }));
methodImpls.Add("UploadString(string someString)", requestBuilder.BuildRestResultFuncForMethod("UploadString", new Type[] { typeof(string) }));
methodImpls.Add("UploadFileInfo(IEnumerable<FileInfo> fileInfos,FileInfo anotherFile)", requestBuilder.BuildRestResultFuncForMethod("UploadFileInfo", new Type[] { typeof(IEnumerable<FileInfo>),typeof(FileInfo) }));
methodImpls.Add("UploadFileInfoPart(IEnumerable<FileInfoPart> fileInfos,FileInfoPart anotherFile)", requestBuilder.BuildRestResultFuncForMethod("UploadFileInfoPart", new Type[] { typeof(IEnumerable<FileInfoPart>),typeof(FileInfoPart) }));
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadStream(Stream stream)
{
var arguments = new object[] { stream };
return (Task<HttpResponseMessage>) methodImpls["UploadStream"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadStream(Stream stream)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadStreamPart(StreamPart stream)
{
var arguments = new object[] { stream };
return (Task<HttpResponseMessage>) methodImpls["UploadStreamPart"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadStreamPart(StreamPart stream)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadBytes(byte[] bytes)
{
var arguments = new object[] { bytes };
return (Task<HttpResponseMessage>) methodImpls["UploadBytes"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadBytes(byte[] bytes)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadBytesPart(ByteArrayPart bytes)
{
var arguments = new object[] { bytes };
return (Task<HttpResponseMessage>) methodImpls["UploadBytesPart"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadBytesPart(ByteArrayPart bytes)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadString(string someString)
{
var arguments = new object[] { someString };
return (Task<HttpResponseMessage>) methodImpls["UploadString"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadString(string someString)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadFileInfo(IEnumerable<FileInfo> fileInfos,FileInfo anotherFile)
{
var arguments = new object[] { fileInfos,anotherFile };
return (Task<HttpResponseMessage>) methodImpls["UploadFileInfo"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadFileInfo(IEnumerable<FileInfo> fileInfos,FileInfo anotherFile)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> UploadFileInfoPart(IEnumerable<FileInfoPart> fileInfos,FileInfoPart anotherFile)
{
var arguments = new object[] { fileInfos,anotherFile };
return (Task<HttpResponseMessage>) methodImpls["UploadFileInfoPart"](Client, arguments);
return (Task<HttpResponseMessage>) methodImpls["UploadFileInfoPart(IEnumerable<FileInfoPart> fileInfos,FileInfoPart anotherFile)"](Client, arguments);
}
}
@ -612,19 +641,73 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIStreamApi(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("GetRemoteFile(string filename)", requestBuilder.BuildRestResultFuncForMethod("GetRemoteFile", new Type[] { typeof(string) }));
}
/// <inheritdoc />
public virtual Task<Stream> GetRemoteFile(string filename)
{
var arguments = new object[] { filename };
return (Task<Stream>) methodImpls["GetRemoteFile"](Client, arguments);
return (Task<Stream>) methodImpls["GetRemoteFile(string filename)"](Client, arguments);
}
}
}
namespace Refit.Tests
{
using RefitInternalGenerated;
/// <inheritdoc />
[Preserve]
public partial class AutoGeneratedIUseOverloadedGenericMethods<TResponse, TParam, THeader> : IUseOverloadedGenericMethods<TResponse, TParam, THeader>
where TResponse : class
where THeader : struct
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIUseOverloadedGenericMethods(HttpClient client, IRequestBuilder requestBuilder)
{
Client = client;
methodImpls.Add("Get()", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { }));
methodImpls.Add("Get(TParam param,THeader header)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(TParam),typeof(THeader) }));
methodImpls.Add("Get(THeader param,TParam header)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(THeader),typeof(TParam) }));
methodImpls.Add("Get(int httpstatuscode)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(int) }));
}
/// <inheritdoc />
public virtual Task<string> Get()
{
var arguments = new object[] { };
return (Task<string>) methodImpls["Get()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<TResponse> Get(TParam param,THeader header)
{
var arguments = new object[] { param,header };
return (Task<TResponse>) methodImpls["Get(TParam param,THeader header)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<TResponse> Get(THeader param,TParam header)
{
var arguments = new object[] { param,header };
return (Task<TResponse>) methodImpls["Get(THeader param,TParam header)"](Client, arguments);
}
/// <inheritdoc />
public virtual Task<HttpResponseMessage> Get(int httpstatuscode)
{
var arguments = new object[] { httpstatuscode };
return (Task<HttpResponseMessage>) methodImpls["Get(int httpstatuscode)"](Client, arguments);
}
}
@ -640,26 +723,27 @@ namespace Refit.Tests
{
/// <inheritdoc />
public HttpClient Client { get; protected set; }
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls;
readonly Dictionary<string, Func<HttpClient, object[], object>> methodImpls = new Dictionary<string, Func<HttpClient, object[], object>>();
public AutoGeneratedIUseOverloadedMethods(HttpClient client, IRequestBuilder requestBuilder)
{
methodImpls = requestBuilder.InterfaceHttpMethods.ToDictionary(k => k, v => requestBuilder.BuildRestResultFuncForMethod(v));
Client = client;
methodImpls.Add("Get()", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { }));
methodImpls.Add("Get(int httpstatuscode)", requestBuilder.BuildRestResultFuncForMethod("Get", new Type[] { typeof(int) }));
}
/// <inheritdoc />
public virtual Task Get()
public virtual Task<string> Get()
{
var arguments = new object[] { };
return (Task) methodImpls["Get"](Client, arguments);
return (Task<string>) methodImpls["Get()"](Client, arguments);
}
/// <inheritdoc />
public virtual Task Get(int id)
public virtual Task<HttpResponseMessage> Get(int httpstatuscode)
{
var arguments = new object[] { id };
return (Task) methodImpls["Get"](Client, arguments);
var arguments = new object[] { httpstatuscode };
return (Task<HttpResponseMessage>) methodImpls["Get(int httpstatuscode)"](Client, arguments);
}
}

Просмотреть файл

@ -153,7 +153,7 @@ namespace Refit.Tests
[Fact]
public void GarbagePathsShouldThrow()
{
bool shouldDie = true;
var shouldDie = true;
try {
var input = typeof(IRestMethodInfoTests);
@ -168,7 +168,7 @@ namespace Refit.Tests
[Fact]
public void MissingParametersShouldBlowUp()
{
bool shouldDie = true;
var shouldDie = true;
try {
var input = typeof(IRestMethodInfoTests);
@ -328,7 +328,7 @@ namespace Refit.Tests
[Fact]
public void SyncMethodsShouldThrow()
{
bool shouldDie = true;
var shouldDie = true;
try {
var input = typeof(IRestMethodInfoTests);
@ -424,9 +424,9 @@ namespace Refit.Tests
interface ICancellableMethods
{
[Get("/foo")]
Task GetWithCancellation(CancellationToken token = default (CancellationToken));
Task GetWithCancellation(CancellationToken token = default);
[Get("/foo")]
Task<string> GetWithCancellationAndReturn(CancellationToken token = default (CancellationToken));
Task<string> GetWithCancellationAndReturn(CancellationToken token = default);
}
@ -577,7 +577,7 @@ namespace Refit.Tests
};
foreach (var v in failureMethods) {
bool shouldDie = true;
var shouldDie = true;
try {
var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));
@ -589,7 +589,7 @@ namespace Refit.Tests
}
foreach (var v in successMethods) {
bool shouldDie = false;
var shouldDie = false;
try {
var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi));

Просмотреть файл

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
@ -461,9 +461,11 @@ namespace Refit.Tests
.WithHeaders("X-Refit", "99")
.Respond("application/json", "{'url': 'https://httpbin.org/get?FirstName=John&LastName=Rambo', 'args': {'FirstName': 'John', 'lName': 'Rambo'}}");
var myParams = new MySimpleQueryParams();
myParams.FirstName = "John";
myParams.LastName = "Rambo";
var myParams = new MySimpleQueryParams
{
FirstName = "John",
LastName = "Rambo"
};
var fixture = RestService.For<IHttpBinApi<HttpBinGet, MySimpleQueryParams, int>>("https://httpbin.org/get", settings);
@ -486,9 +488,11 @@ namespace Refit.Tests
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/get")
.Respond("application/json", "{'url': 'https://httpbin.org/get?hardcoded=true&FirstName=John&LastName=Rambo&Addr_Zip=9999&Addr_Street=HomeStreet 99&MetaData_Age=99&MetaData_Initials=JR&MetaData_Birthday=10%2F31%2F1918 4%3A21%3A16 PM&Other=12345&Other=10%2F31%2F2017 4%3A21%3A17 PM&Other=696e8653-6671-4484-a65f-9485af95fd3a', 'args': { 'Addr_Street': 'HomeStreet 99', 'Addr_Zip': '9999', 'FirstName': 'John', 'LastName': 'Rambo', 'MetaData_Age': '99', 'MetaData_Birthday': '10/31/1981 4:32:59 PM', 'MetaData_Initials': 'JR', 'Other': ['12345','10/31/2017 4:32:59 PM','60282dd2-f79a-4400-be01-bcb0e86e7bc6'], 'hardcoded': 'true'}}");
var myParams = new MyComplexQueryParams();
myParams.FirstName = "John";
myParams.LastName = "Rambo";
var myParams = new MyComplexQueryParams
{
FirstName = "John",
LastName = "Rambo"
};
myParams.Address.Postcode = 9999;
myParams.Address.Street = "HomeStreet 99";
@ -523,14 +527,15 @@ namespace Refit.Tests
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/get")
.Respond("application/json", "{'url': 'https://httpbin.org/get?hardcoded=true&FirstName=John&LastName=Rambo&Address_Zip=9999&Address_Street=HomeStreet 99', 'args': {'Address_Street': 'HomeStreet 99','Address_Zip': '9999','FirstName': 'John','LastName': 'Rambo','hardcoded': 'true'}}");
var myParams = new Dictionary<string, object>();
myParams["FirstName"] = "John";
myParams["LastName"] = "Rambo";
myParams["Address"] = new
var myParams = new Dictionary<string, object>
{
Zip = 9999,
Street = "HomeStreet 99"
["FirstName"] = "John",
["LastName"] = "Rambo",
["Address"] = new
{
Zip = 9999,
Street = "HomeStreet 99"
}
};
var fixture = RestService.For<IHttpBinApi<HttpBinGet, Dictionary<string, object>, int>>("https://httpbin.org", settings);
@ -555,9 +560,11 @@ namespace Refit.Tests
mockHttp.Expect(HttpMethod.Get, "https://httpbin.org/get")
.Respond("application/json", "{'url': 'https://httpbin.org/get?search.FirstName=John&search.LastName=Rambo&search.Addr.Zip=9999&search.Addr.Street=HomeStreet 99', 'args': {'search.Addr.Street': 'HomeStreet 99','search.Addr.Zip': '9999','search.FirstName': 'John','search.LastName': 'Rambo'}}");
var myParams = new MyComplexQueryParams();
myParams.FirstName = "John";
myParams.LastName = "Rambo";
var myParams = new MyComplexQueryParams
{
FirstName = "John",
LastName = "Rambo"
};
myParams.Address.Postcode = 9999;
myParams.Address.Street = "HomeStreet 99";

Просмотреть файл

@ -35,7 +35,7 @@ namespace Refit
public T GetContentAs<T>() => HasContent ?
JsonConvert.DeserializeObject<T>(Content, RefitSettings.JsonSerializerSettings) :
default(T);
default;
#pragma warning disable VSTHRD200 // Use "Async" suffix for async methods
public static async Task<ApiException> Create(Uri uri, HttpMethod httpMethod, HttpResponseMessage response, RefitSettings refitSettings = null)

Просмотреть файл

@ -106,7 +106,7 @@ namespace System.Net.Http
{
onStreamAvailable(stream, content, transportContext);
// https://github.com/ASP-NET-MVC/aspnetwebstack/blob/5118a14040b13f95bf778d1fc4522eb4ea2eef18/src/Common/TaskHelpers.cs#L10
return Task.FromResult<AsyncVoid>(default(AsyncVoid));
return Task.FromResult<AsyncVoid>(default);
};
}
@ -300,4 +300,4 @@ namespace System.Net.Http
innerStream.WriteByte(value);
}
}
}
}

Просмотреть файл

@ -8,8 +8,7 @@ namespace Refit
{
public interface IRequestBuilder
{
IEnumerable<string> InterfaceHttpMethods { get; }
Func<HttpClient, object[], object> BuildRestResultFuncForMethod(string methodName);
Func<HttpClient, object[], object> BuildRestResultFuncForMethod(string methodName, Type[] parameterTypes = null);
}
public static class RequestBuilder

Просмотреть файл

@ -16,7 +16,7 @@ namespace Refit
{
partial class RequestBuilderImplementation : IRequestBuilder
{
readonly Dictionary<string, RestMethodInfo> interfaceHttpMethods;
readonly Dictionary<string, List<RestMethodInfo>> interfaceHttpMethods;
readonly JsonSerializer serializer;
readonly RefitSettings settings;
readonly Type targetType;
@ -32,24 +32,86 @@ namespace Refit
}
targetType = targetInterface;
interfaceHttpMethods = targetInterface.GetMethods()
.Where(x => x.GetCustomAttributes(true)
.OfType<HttpMethodAttribute>().Any())
.Select(x => new RestMethodInfo(targetInterface, x, settings))
.ToDictionary(k => k.Name, v => v);
var dict = new Dictionary<string, List<RestMethodInfo>>();
foreach (var methodInfo in targetInterface.GetMethods())
{
var attrs = methodInfo.GetCustomAttributes(true);
var hasHttpMethod = attrs.OfType<HttpMethodAttribute>().Any();
if (hasHttpMethod)
{
if (!dict.ContainsKey(methodInfo.Name))
{
dict.Add(methodInfo.Name, new List<RestMethodInfo>());
}
var restinfo = new RestMethodInfo(targetInterface, methodInfo, settings);
dict[methodInfo.Name].Add(restinfo);
}
}
interfaceHttpMethods = dict;
}
public IEnumerable<string> InterfaceHttpMethods => interfaceHttpMethods.Keys;
RestMethodInfo FindMatchingRestMethodInfo(string key, Type[] parameterTypes)
{
if (interfaceHttpMethods.TryGetValue(key, out var httpMethods))
{
if (parameterTypes == null)
{
if (httpMethods.Count > 1)
{
throw new ArgumentException($"MethodName exists more than once, '{nameof(parameterTypes)}' mut be defined");
}
return httpMethods[0];
}
public Func<HttpClient, object[], object> BuildRestResultFuncForMethod(string methodName)
var possibleMethods = httpMethods.Where(method => method.MethodInfo.GetParameters().Length == parameterTypes.Count())
.ToList();
if (possibleMethods.Count == 1)
return possibleMethods[0];
var parameterTypesArray = parameterTypes.ToArray();
foreach (var method in possibleMethods)
{
var match = true;
var parameters = method.MethodInfo.GetParameters();
for (var i = 0; i < parameterTypesArray.Length; i++)
{
var arg = parameterTypesArray[i];
var paramType = parameters[i].ParameterType;
if (arg != paramType)
{
match = false;
break;
}
}
if (match)
{
return method;
}
}
throw new Exception("No suitable Method found...");
}
else
{
throw new ArgumentException("Method must be defined and have an HTTP Method attribute");
}
}
public Func<HttpClient, object[], object> BuildRestResultFuncForMethod(string methodName, Type[] parameterTypes = null)
{
if (!interfaceHttpMethods.ContainsKey(methodName))
{
throw new ArgumentException("Method must be defined and have an HTTP Method attribute");
}
var restMethod = interfaceHttpMethods[methodName];
var restMethod = FindMatchingRestMethodInfo(methodName, parameterTypes);
if (restMethod.ReturnType == typeof(Task))
{
return BuildVoidTaskFuncForMethod(restMethod);
@ -65,7 +127,7 @@ namespace Refit
var taskFunc = (MulticastDelegate)taskFuncMi.MakeGenericMethod(restMethod.SerializedReturnType)
.Invoke(this, new[] { restMethod });
return (client, args) => { return taskFunc.DynamicInvoke(client, args); };
return (client, args) => taskFunc.DynamicInvoke(client, args);
}
// Same deal
@ -73,31 +135,27 @@ namespace Refit
var rxFunc = (MulticastDelegate)rxFuncMi.MakeGenericMethod(restMethod.SerializedReturnType)
.Invoke(this, new[] { restMethod });
return (client, args) => { return rxFunc.DynamicInvoke(client, args); };
return (client, args) => rxFunc.DynamicInvoke(client, args);
}
void AddMultipartItem(MultipartFormDataContent multiPartContent, string fileName, string parameterName, object itemValue)
{
var multipartItem = itemValue as MultipartItem;
var streamValue = itemValue as Stream;
var stringValue = itemValue as string;
var byteArrayValue = itemValue as byte[];
if (multipartItem != null)
if (itemValue is MultipartItem multipartItem)
{
var httpContent = multipartItem.ToContent();
multiPartContent.Add(httpContent, parameterName, string.IsNullOrEmpty(multipartItem.FileName) ? fileName : multipartItem.FileName);
return;
}
if (streamValue != null)
if (itemValue is Stream streamValue)
{
var streamContent = new StreamContent(streamValue);
multiPartContent.Add(streamContent, parameterName, fileName);
return;
}
if (stringValue != null)
if (itemValue is string stringValue)
{
multiPartContent.Add(new StringContent(stringValue), parameterName, fileName);
return;
@ -110,8 +168,7 @@ namespace Refit
return;
}
if (byteArrayValue != null)
{
if (itemValue is byte[] byteArrayValue) {
var fileContent = new ByteArrayContent(byteArrayValue);
multiPartContent.Add(fileContent, parameterName, fileName);
return;
@ -127,7 +184,7 @@ namespace Refit
if (client.BaseAddress == null)
throw new InvalidOperationException("BaseAddress must be set on the HttpClient instance");
var factory = BuildRequestFactoryForMethod(restMethod.Name, client.BaseAddress.AbsolutePath, restMethod.CancellationToken != null);
var factory = BuildRequestFactoryForMethod(restMethod, client.BaseAddress.AbsolutePath, restMethod.CancellationToken != null);
var rq = factory(paramList);
HttpResponseMessage resp = null;
var disposeResponse = true;
@ -271,15 +328,9 @@ namespace Refit
return kvps;
}
Func<object[], HttpRequestMessage> BuildRequestFactoryForMethod(string methodName, string basePath, bool paramsContainsCancellationToken)
Func<object[], HttpRequestMessage> BuildRequestFactoryForMethod(RestMethodInfo restMethod, string basePath, bool paramsContainsCancellationToken)
{
if (!interfaceHttpMethods.ContainsKey(methodName))
{
throw new ArgumentException("Method must be defined and have an HTTP Method attribute");
}
var restMethod = interfaceHttpMethods[methodName];
return paramList =>
{
// make sure we strip out any cancelation tokens
@ -470,7 +521,7 @@ namespace Refit
// parameters as well as add the parameterized ones.
var uri = new UriBuilder(new Uri(new Uri("http://api"), urlTarget));
var query = HttpUtility.ParseQueryString(uri.Query ?? "");
foreach (string key in query.AllKeys)
foreach (var key in query.AllKeys)
{
queryParamsToAdd.Insert(0, new KeyValuePair<string, string>(key, query[key]));
}
@ -533,7 +584,7 @@ namespace Refit
if (client.BaseAddress == null)
throw new InvalidOperationException("BaseAddress must be set on the HttpClient instance");
var factory = BuildRequestFactoryForMethod(restMethod.Name, client.BaseAddress.AbsolutePath, restMethod.CancellationToken != null);
var factory = BuildRequestFactoryForMethod(restMethod, client.BaseAddress.AbsolutePath, restMethod.CancellationToken != null);
var rq = factory(paramList);
var ct = CancellationToken.None;