A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/reactiveui/refit/commit/c8888e12d7f7f96539eca1f131d99ef0c9f58b81 below:

Fix condition of method return type in RequestBuilder to only allow T… · reactiveui/refit@c8888e1 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+15

-3

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+15

-3

lines changed Original file line number Diff line number Diff line change

@@ -250,6 +250,9 @@ public interface IRestMethodInfoTests

250 250 251 251

[Get("/api/{id}")]

252 252

Task IEnumerableThrowingError([Query(CollectionFormat.Multi)] IEnumerable<string> values);

253 + 254 +

[Get("/foo")]

255 +

List<string> InvalidGenericReturnType();

253 256

}

254 257 255 258

public enum TestEnum { A, B, C }

@@ -1146,6 +1149,14 @@ public void ParameterMappingWithHeaderQueryParamAndQueryArrayParam()

1146 1149

Assert.Single(fixture.HeaderParameterMap);

1147 1150

Assert.Single(fixture.PropertyParameterMap);

1148 1151

}

1152 + 1153 +

[Fact]

1154 +

public void GenericReturnTypeIsNotTaskOrObservableShouldThrow()

1155 +

{

1156 +

var input = typeof(IRestMethodInfoTests);

1157 +

Assert.Throws<ArgumentException>(() => new RestMethodInfo(input,

1158 +

input.GetMethods().First(x => x.Name == nameof(IRestMethodInfoTests.InvalidGenericReturnType))));

1159 +

}

1149 1160

}

1150 1161 1151 1162

[Headers("User-Agent: RefitTestClient", "Api-Version: 1")]

Original file line number Diff line number Diff line change

@@ -463,8 +463,9 @@ static Dictionary<int, string> BuildHeaderParameterMap(List<ParameterInfo> param

463 463

void DetermineReturnTypeInfo(MethodInfo methodInfo)

464 464

{

465 465

var returnType = methodInfo.ReturnType;

466 -

if (returnType.IsGenericType && (methodInfo.ReturnType.GetGenericTypeDefinition() != typeof(Task<>)

467 -

|| methodInfo.ReturnType.GetGenericTypeDefinition() != typeof(IObservable<>)))

466 +

if (returnType.IsGenericType && (methodInfo.ReturnType.GetGenericTypeDefinition() == typeof(Task<>)

467 +

|| methodInfo.ReturnType.GetGenericTypeDefinition() == typeof(ValueTask<>)

468 +

|| methodInfo.ReturnType.GetGenericTypeDefinition() == typeof(IObservable<>)))

468 469

{

469 470

ReturnType = returnType;

470 471

ReturnResultType = returnType.GetGenericArguments()[0];

@@ -488,7 +489,7 @@ void DetermineReturnTypeInfo(MethodInfo methodInfo)

488 489

DeserializedResultType = typeof(void);

489 490

}

490 491

else

491 -

throw new ArgumentException($"Method \"{methodInfo.Name}\" is invalid. All REST Methods must return either Task<T> or IObservable<T>");

492 +

throw new ArgumentException($"Method \"{methodInfo.Name}\" is invalid. All REST Methods must return either Task<T> or ValueTask<T> or IObservable<T>");

492 493

}

493 494 494 495

void DetermineIfResponseMustBeDisposed()

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4