Skip to content

Commit 2dff048

Browse files
housekeeping: run csharpier (#1617)
1 parent bca7448 commit 2dff048

File tree

71 files changed

+4842
-2341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4842
-2341
lines changed

InterfaceStubGenerator.Shared/ITypeSymbolExtensions.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@ public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? typ
2222
// Determine if "type" inherits from "baseType", ignoring constructed types, optionally including interfaces,
2323
// dealing only with original types.
2424
public static bool InheritsFromOrEquals(
25-
this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces)
25+
this ITypeSymbol type,
26+
ITypeSymbol baseType,
27+
bool includeInterfaces
28+
)
2629
{
2730
if (!includeInterfaces)
2831
{
2932
return InheritsFromOrEquals(type, baseType);
3033
}
3134

32-
return type.GetBaseTypesAndThis().Concat(type.AllInterfaces).Any(t => t.Equals(baseType, SymbolEqualityComparer.Default));
35+
return type.GetBaseTypesAndThis()
36+
.Concat(type.AllInterfaces)
37+
.Any(t => t.Equals(baseType, SymbolEqualityComparer.Default));
3338
}
3439

35-
3640
// Determine if "type" inherits from "baseType", ignoring constructed types and interfaces, dealing
3741
// only with original types.
38-
public static bool InheritsFromOrEquals(
39-
this ITypeSymbol type, ITypeSymbol baseType)
42+
public static bool InheritsFromOrEquals(this ITypeSymbol type, ITypeSymbol baseType)
4043
{
41-
return type.GetBaseTypesAndThis().Any(t => t.Equals(baseType, SymbolEqualityComparer.Default));
44+
return type.GetBaseTypesAndThis()
45+
.Any(t => t.Equals(baseType, SymbolEqualityComparer.Default));
4246
}
43-
4447
}
4548
}

InterfaceStubGenerator.Shared/InterfaceStubGenerator.cs

Lines changed: 308 additions & 150 deletions
Large diffs are not rendered by default.

Refit.Benchmarks/EndToEndBenchmark.cs

Lines changed: 113 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,33 @@ public class EndToEndBenchmark
1212
private const string Host = "https://github.com";
1313
private SystemTextJsonContentSerializer systemTextJsonContentSerializer;
1414
private NewtonsoftJsonContentSerializer newtonsoftJsonContentSerializer;
15-
private readonly IDictionary<int, IEnumerable<User>> users = new Dictionary<int, IEnumerable<User>>();
16-
private readonly IDictionary<SerializationStrategy, IDictionary<HttpStatusCode ,IGitHubService>> refitClient = new Dictionary<SerializationStrategy, IDictionary<HttpStatusCode ,IGitHubService>>
15+
private readonly IDictionary<int, IEnumerable<User>> users =
16+
new Dictionary<int, IEnumerable<User>>();
17+
private readonly IDictionary<
18+
SerializationStrategy,
19+
IDictionary<HttpStatusCode, IGitHubService>
20+
> refitClient = new Dictionary<
21+
SerializationStrategy,
22+
IDictionary<HttpStatusCode, IGitHubService>
23+
>
1724
{
18-
{SerializationStrategy.SystemTextJson, new Dictionary<HttpStatusCode, IGitHubService>()},
19-
{SerializationStrategy.NewtonsoftJson, new Dictionary<HttpStatusCode, IGitHubService>()}
25+
{
26+
SerializationStrategy.SystemTextJson,
27+
new Dictionary<HttpStatusCode, IGitHubService>()
28+
},
29+
{
30+
SerializationStrategy.NewtonsoftJson,
31+
new Dictionary<HttpStatusCode, IGitHubService>()
32+
}
2033
};
2134

22-
private readonly IDictionary<HttpVerb, HttpMethod> httpMethod = new Dictionary<HttpVerb, HttpMethod>
35+
private readonly IDictionary<HttpVerb, HttpMethod> httpMethod = new Dictionary<
36+
HttpVerb,
37+
HttpMethod
38+
>
2339
{
24-
{HttpVerb.Get, HttpMethod.Get}, {HttpVerb.Post, HttpMethod.Post}
40+
{ HttpVerb.Get, HttpMethod.Get },
41+
{ HttpVerb.Post, HttpMethod.Post }
2542
};
2643

2744
private const int TenUsers = 10;
@@ -41,26 +58,57 @@ public enum HttpVerb
4158
[GlobalSetup]
4259
public Task SetupAsync()
4360
{
44-
4561
systemTextJsonContentSerializer = new SystemTextJsonContentSerializer();
46-
refitClient[SerializationStrategy.SystemTextJson][HttpStatusCode.OK] = RestService.For<IGitHubService>(Host, new RefitSettings(systemTextJsonContentSerializer)
47-
{
48-
HttpMessageHandlerFactory = () => new StaticFileHttpResponseHandler("system-text-json-10-users.json", HttpStatusCode.OK)
49-
});
50-
refitClient[SerializationStrategy.SystemTextJson][HttpStatusCode.InternalServerError] = RestService.For<IGitHubService>(Host, new RefitSettings(systemTextJsonContentSerializer)
51-
{
52-
HttpMessageHandlerFactory = () => new StaticFileHttpResponseHandler("system-text-json-10-users.json", HttpStatusCode.InternalServerError)
53-
});
62+
refitClient[SerializationStrategy.SystemTextJson][HttpStatusCode.OK] =
63+
RestService.For<IGitHubService>(
64+
Host,
65+
new RefitSettings(systemTextJsonContentSerializer)
66+
{
67+
HttpMessageHandlerFactory = () =>
68+
new StaticFileHttpResponseHandler(
69+
"system-text-json-10-users.json",
70+
HttpStatusCode.OK
71+
)
72+
}
73+
);
74+
refitClient[SerializationStrategy.SystemTextJson][HttpStatusCode.InternalServerError] =
75+
RestService.For<IGitHubService>(
76+
Host,
77+
new RefitSettings(systemTextJsonContentSerializer)
78+
{
79+
HttpMessageHandlerFactory = () =>
80+
new StaticFileHttpResponseHandler(
81+
"system-text-json-10-users.json",
82+
HttpStatusCode.InternalServerError
83+
)
84+
}
85+
);
5486

5587
newtonsoftJsonContentSerializer = new NewtonsoftJsonContentSerializer();
56-
refitClient[SerializationStrategy.NewtonsoftJson][HttpStatusCode.OK] = RestService.For<IGitHubService>(Host, new RefitSettings(newtonsoftJsonContentSerializer)
57-
{
58-
HttpMessageHandlerFactory = () => new StaticFileHttpResponseHandler("newtonsoft-json-10-users.json", System.Net.HttpStatusCode.OK)
59-
});
60-
refitClient[SerializationStrategy.NewtonsoftJson][HttpStatusCode.InternalServerError] = RestService.For<IGitHubService>(Host, new RefitSettings(newtonsoftJsonContentSerializer)
61-
{
62-
HttpMessageHandlerFactory = () => new StaticFileHttpResponseHandler("newtonsoft-json-10-users.json", System.Net.HttpStatusCode.InternalServerError)
63-
});
88+
refitClient[SerializationStrategy.NewtonsoftJson][HttpStatusCode.OK] =
89+
RestService.For<IGitHubService>(
90+
Host,
91+
new RefitSettings(newtonsoftJsonContentSerializer)
92+
{
93+
HttpMessageHandlerFactory = () =>
94+
new StaticFileHttpResponseHandler(
95+
"newtonsoft-json-10-users.json",
96+
System.Net.HttpStatusCode.OK
97+
)
98+
}
99+
);
100+
refitClient[SerializationStrategy.NewtonsoftJson][HttpStatusCode.InternalServerError] =
101+
RestService.For<IGitHubService>(
102+
Host,
103+
new RefitSettings(newtonsoftJsonContentSerializer)
104+
{
105+
HttpMessageHandlerFactory = () =>
106+
new StaticFileHttpResponseHandler(
107+
"newtonsoft-json-10-users.json",
108+
System.Net.HttpStatusCode.InternalServerError
109+
)
110+
}
111+
);
64112

65113
users[TenUsers] = autoFixture.CreateMany<User>(TenUsers);
66114

@@ -94,7 +142,9 @@ public async Task Task_Async()
94142
await refitClient[Serializer][HttpStatusCode].GetUsersTaskAsync();
95143
break;
96144
case HttpVerb.Post:
97-
await refitClient[Serializer][HttpStatusCode].PostUsersTaskAsync(users[ModelCount]);
145+
await refitClient[Serializer][HttpStatusCode].PostUsersTaskAsync(
146+
users[ModelCount]
147+
);
98148
break;
99149
default:
100150
throw new ArgumentOutOfRangeException(nameof(Verb));
@@ -114,9 +164,13 @@ public async Task<string> TaskString_Async()
114164
switch (Verb)
115165
{
116166
case HttpVerb.Get:
117-
return await refitClient[Serializer][HttpStatusCode].GetUsersTaskStringAsync();
167+
return await refitClient[Serializer][
168+
HttpStatusCode
169+
].GetUsersTaskStringAsync();
118170
case HttpVerb.Post:
119-
return await refitClient[Serializer][HttpStatusCode].PostUsersTaskStringAsync(users[ModelCount]);
171+
return await refitClient[Serializer][
172+
HttpStatusCode
173+
].PostUsersTaskStringAsync(users[ModelCount]);
120174
default:
121175
throw new ArgumentOutOfRangeException(nameof(Verb));
122176
}
@@ -137,9 +191,13 @@ public async Task<Stream> TaskStream_Async()
137191
switch (Verb)
138192
{
139193
case HttpVerb.Get:
140-
return await refitClient[Serializer][HttpStatusCode].GetUsersTaskStreamAsync();
194+
return await refitClient[Serializer][
195+
HttpStatusCode
196+
].GetUsersTaskStreamAsync();
141197
case HttpVerb.Post:
142-
return await refitClient[Serializer][HttpStatusCode].PostUsersTaskStreamAsync(users[ModelCount]);
198+
return await refitClient[Serializer][
199+
HttpStatusCode
200+
].PostUsersTaskStreamAsync(users[ModelCount]);
143201
default:
144202
throw new ArgumentOutOfRangeException(nameof(Verb));
145203
}
@@ -160,9 +218,13 @@ public async Task<HttpContent> TaskHttpContent_Async()
160218
switch (Verb)
161219
{
162220
case HttpVerb.Get:
163-
return await refitClient[Serializer][HttpStatusCode].GetUsersTaskHttpContentAsync();
221+
return await refitClient[Serializer][
222+
HttpStatusCode
223+
].GetUsersTaskHttpContentAsync();
164224
case HttpVerb.Post:
165-
return await refitClient[Serializer][HttpStatusCode].PostUsersTaskHttpContentAsync(users[ModelCount]);
225+
return await refitClient[Serializer][
226+
HttpStatusCode
227+
].PostUsersTaskHttpContentAsync(users[ModelCount]);
166228
default:
167229
throw new ArgumentOutOfRangeException(nameof(Verb));
168230
}
@@ -181,9 +243,13 @@ public async Task<HttpResponseMessage> TaskHttpResponseMessage_Async()
181243
switch (Verb)
182244
{
183245
case HttpVerb.Get:
184-
return await refitClient[Serializer][HttpStatusCode].GetUsersTaskHttpResponseMessageAsync();
246+
return await refitClient[Serializer][
247+
HttpStatusCode
248+
].GetUsersTaskHttpResponseMessageAsync();
185249
case HttpVerb.Post:
186-
return await refitClient[Serializer][HttpStatusCode].PostUsersTaskHttpResponseMessageAsync(users[ModelCount]);
250+
return await refitClient[Serializer][
251+
HttpStatusCode
252+
].PostUsersTaskHttpResponseMessageAsync(users[ModelCount]);
187253
default:
188254
throw new ArgumentOutOfRangeException(nameof(Verb));
189255
}
@@ -195,9 +261,13 @@ public IObservable<HttpResponseMessage> ObservableHttpResponseMessage()
195261
switch (Verb)
196262
{
197263
case HttpVerb.Get:
198-
return refitClient[Serializer][HttpStatusCode].GetUsersObservableHttpResponseMessage();
264+
return refitClient[Serializer][
265+
HttpStatusCode
266+
].GetUsersObservableHttpResponseMessage();
199267
case HttpVerb.Post:
200-
return refitClient[Serializer][HttpStatusCode].PostUsersObservableHttpResponseMessage(users[ModelCount]);
268+
return refitClient[Serializer][
269+
HttpStatusCode
270+
].PostUsersObservableHttpResponseMessage(users[ModelCount]);
201271
default:
202272
throw new ArgumentOutOfRangeException(nameof(Verb));
203273
}
@@ -213,7 +283,9 @@ public async Task<List<User>> TaskT_Async()
213283
case HttpVerb.Get:
214284
return await refitClient[Serializer][HttpStatusCode].GetUsersTaskTAsync();
215285
case HttpVerb.Post:
216-
return await refitClient[Serializer][HttpStatusCode].PostUsersTaskTAsync(users[ModelCount]);
286+
return await refitClient[Serializer][HttpStatusCode].PostUsersTaskTAsync(
287+
users[ModelCount]
288+
);
217289
default:
218290
throw new ArgumentOutOfRangeException(nameof(Verb));
219291
}
@@ -232,9 +304,13 @@ public async Task<ApiResponse<List<User>>> TaskApiResponseT_Async()
232304
switch (Verb)
233305
{
234306
case HttpVerb.Get:
235-
return await refitClient[Serializer][HttpStatusCode].GetUsersTaskApiResponseTAsync();
307+
return await refitClient[Serializer][
308+
HttpStatusCode
309+
].GetUsersTaskApiResponseTAsync();
236310
case HttpVerb.Post:
237-
return await refitClient[Serializer][HttpStatusCode].PostUsersTaskApiResponseTAsync(users[ModelCount]);
311+
return await refitClient[Serializer][
312+
HttpStatusCode
313+
].PostUsersTaskApiResponseTAsync(users[ModelCount]);
238314
default:
239315
throw new ArgumentOutOfRangeException(nameof(Verb));
240316
}

Refit.Benchmarks/IGitHubService.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,64 @@ public interface IGitHubService
55
//Task - throws
66
[Get("/users")]
77
public Task GetUsersTaskAsync();
8+
89
[Post("/users")]
910
public Task PostUsersTaskAsync([Body] IEnumerable<User> users);
1011

1112
//Task<string> - throws
1213
[Get("/users")]
1314
public Task<string> GetUsersTaskStringAsync();
15+
1416
[Post("/users")]
1517
public Task<string> PostUsersTaskStringAsync([Body] IEnumerable<User> users);
1618

1719
//Task<Stream> - throws
1820
[Get("/users")]
1921
public Task<Stream> GetUsersTaskStreamAsync();
22+
2023
[Post("/users")]
2124
public Task<Stream> PostUsersTaskStreamAsync([Body] IEnumerable<User> users);
2225

2326
//Task<HttpContent> - throws
2427
[Get("/users")]
2528
public Task<HttpContent> GetUsersTaskHttpContentAsync();
29+
2630
[Post("/users")]
2731
public Task<HttpContent> PostUsersTaskHttpContentAsync([Body] IEnumerable<User> users);
2832

2933
//Task<HttpResponseMessage>
3034
[Get("/users")]
3135
public Task<HttpResponseMessage> GetUsersTaskHttpResponseMessageAsync();
36+
3237
[Post("/users")]
33-
public Task<HttpResponseMessage> PostUsersTaskHttpResponseMessageAsync([Body] IEnumerable<User> users);
38+
public Task<HttpResponseMessage> PostUsersTaskHttpResponseMessageAsync(
39+
[Body] IEnumerable<User> users
40+
);
3441

3542
//IObservable<HttpResponseMessage>
3643
[Get("/users")]
3744
public IObservable<HttpResponseMessage> GetUsersObservableHttpResponseMessage();
45+
3846
[Post("/users")]
39-
public IObservable<HttpResponseMessage> PostUsersObservableHttpResponseMessage([Body] IEnumerable<User> users);
47+
public IObservable<HttpResponseMessage> PostUsersObservableHttpResponseMessage(
48+
[Body] IEnumerable<User> users
49+
);
4050

4151
//Task<<T>> - throws
4252
[Get("/users")]
4353
public Task<List<User>> GetUsersTaskTAsync();
54+
4455
[Post("/users")]
4556
public Task<List<User>> PostUsersTaskTAsync([Body] IEnumerable<User> users);
4657

4758
//Task<ApiResponse<T>>
4859
[Get("/users")]
4960
public Task<ApiResponse<List<User>>> GetUsersTaskApiResponseTAsync();
61+
5062
[Post("/users")]
51-
public Task<ApiResponse<List<User>>> PostUsersTaskApiResponseTAsync([Body] IEnumerable<User> users);
63+
public Task<ApiResponse<List<User>>> PostUsersTaskApiResponseTAsync(
64+
[Body] IEnumerable<User> users
65+
);
5266
}
5367

5468
public class User
@@ -61,5 +75,3 @@ public class User
6175
public string Url { get; set; }
6276
}
6377
}
64-
65-

Refit.Benchmarks/StaticFileHttpResponseHandler.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ public StaticFileHttpResponseHandler(string fileName, HttpStatusCode responseCod
1313
throw new ArgumentNullException(nameof(fileName));
1414

1515
responsePayload = File.ReadAllText(fileName);
16-
; this.responseCode = responseCode;
16+
;
17+
this.responseCode = responseCode;
1718
}
1819

19-
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
20-
CancellationToken cancellationToken)
20+
protected override Task<HttpResponseMessage> SendAsync(
21+
HttpRequestMessage request,
22+
CancellationToken cancellationToken
23+
)
2124
{
22-
return Task.FromResult(new HttpResponseMessage(responseCode)
23-
{
24-
RequestMessage = request,
25-
Content = new StringContent(responsePayload)
26-
});
25+
return Task.FromResult(
26+
new HttpResponseMessage(responseCode)
27+
{
28+
RequestMessage = request,
29+
Content = new StringContent(responsePayload)
30+
}
31+
);
2732
}
2833
}
2934
}

0 commit comments

Comments
 (0)