Skip to content

Commit db0b9fa

Browse files
committed
fix IDE informations (C# 7.1-8.0 features)
1 parent 868f67a commit db0b9fa

File tree

3 files changed

+58
-77
lines changed

3 files changed

+58
-77
lines changed

src/MicroBatchFramework.WebHosting/BatchEngineSwaggerMiddleware.cs

Lines changed: 48 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -42,86 +42,69 @@ public async Task Invoke(HttpContext httpContext)
4242

4343
var myAssembly = typeof(BatchEngineSwaggerMiddleware).GetTypeInfo().Assembly;
4444

45-
using (var stream = myAssembly.GetManifestResourceStream(filePath))
45+
using var stream = myAssembly.GetManifestResourceStream(filePath);
46+
if (options.ResolveCustomResource == null)
4647
{
47-
if (options.ResolveCustomResource == null)
48+
if (stream == null)
4849
{
49-
if (stream == null)
50-
{
51-
// not found, standard request.
52-
await next(httpContext);
53-
return;
54-
}
50+
// not found, standard request.
51+
await next(httpContext);
52+
return;
53+
}
5554

56-
httpContext.Response.Headers["Content-Type"] = new[] { mediaType };
57-
httpContext.Response.StatusCode = 200;
58-
var response = httpContext.Response.Body;
59-
await stream.CopyToAsync(response);
55+
httpContext.Response.Headers["Content-Type"] = new[] { mediaType };
56+
httpContext.Response.StatusCode = 200;
57+
var response = httpContext.Response.Body;
58+
await stream.CopyToAsync(response);
59+
}
60+
else
61+
{
62+
byte[] bytes;
63+
if (stream == null)
64+
{
65+
bytes = options.ResolveCustomResource(path, null);
6066
}
6167
else
6268
{
63-
byte[] bytes;
64-
if (stream == null)
65-
{
66-
bytes = options.ResolveCustomResource(path, null);
67-
}
68-
else
69-
{
70-
using (var ms = new MemoryStream())
71-
{
72-
await stream.CopyToAsync(ms);
73-
bytes = options.ResolveCustomResource(path, ms.ToArray());
74-
}
75-
}
76-
77-
if (bytes == null)
78-
{
79-
// not found, standard request.
80-
await next(httpContext);
81-
return;
82-
}
69+
using var ms = new MemoryStream();
70+
await stream.CopyToAsync(ms);
71+
bytes = options.ResolveCustomResource(path, ms.ToArray());
72+
}
8373

84-
httpContext.Response.Headers["Content-Type"] = new[] { mediaType };
85-
httpContext.Response.StatusCode = 200;
86-
var response = httpContext.Response.Body;
87-
await response.WriteAsync(bytes, 0, bytes.Length);
74+
if (bytes == null)
75+
{
76+
// not found, standard request.
77+
await next(httpContext);
78+
return;
8879
}
80+
81+
httpContext.Response.Headers["Content-Type"] = new[] { mediaType };
82+
httpContext.Response.StatusCode = 200;
83+
var response = httpContext.Response.Body;
84+
await response.WriteAsync(bytes, 0, bytes.Length);
8985
}
9086
}
9187

92-
static string GetMediaType(string path)
88+
private static string GetMediaType(string path)
9389
{
9490
var extension = path.Split('.').Last();
9591

96-
switch (extension)
92+
return extension switch
9793
{
98-
case "css":
99-
return "text/css";
100-
case "js":
101-
return "text/javascript";
102-
case "json":
103-
return "application/json";
104-
case "gif":
105-
return "image/gif";
106-
case "png":
107-
return "image/png";
108-
case "eot":
109-
return "application/vnd.ms-fontobject";
110-
case "woff":
111-
return "application/font-woff";
112-
case "woff2":
113-
return "application/font-woff2";
114-
case "otf":
115-
return "application/font-sfnt";
116-
case "ttf":
117-
return "application/font-sfnt";
118-
case "svg":
119-
return "image/svg+xml";
120-
case "ico":
121-
return "image/x-icon";
122-
default:
123-
return "text/html";
124-
}
94+
"css" => "text/css",
95+
"js" => "text/javascript",
96+
"json" => "application/json",
97+
"gif" => "image/gif",
98+
"png" => "image/png",
99+
"eot" => "application/vnd.ms-fontobject",
100+
"woff" => "application/font-woff",
101+
"woff2" => "application/font-woff2",
102+
"otf" => "application/font-sfnt",
103+
"ttf" => "application/font-sfnt",
104+
"svg" => "image/svg+xml",
105+
"ico" => "image/x-icon",
106+
_ => "text/html",
107+
};
125108
}
126109
}
127110
}

src/MicroBatchFramework.WebHosting/Swagger/SwaggerDefinitionBuilder.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,17 @@ public byte[] BuildSwaggerJson()
105105
doc.paths.Add("/" + declaringTypeName + "/" + item.Name, new PathItem { post = operation }); // everything post.
106106
}
107107

108-
using (var ms = new MemoryStream())
109-
using (var sw = new StreamWriter(ms, new UTF8Encoding(false)))
108+
using var ms = new MemoryStream();
109+
using var sw = new StreamWriter(ms, new UTF8Encoding(false));
110+
var serializer = new JsonSerializer()
110111
{
111-
var serializer = new JsonSerializer()
112-
{
113-
NullValueHandling = NullValueHandling.Ignore,
114-
ContractResolver = IgnoreEmptyEnumerablesResolver.Instance // omit empty collection.
115-
};
116-
serializer.Serialize(sw, doc);
112+
NullValueHandling = NullValueHandling.Ignore,
113+
ContractResolver = IgnoreEmptyEnumerablesResolver.Instance // omit empty collection.
114+
};
115+
serializer.Serialize(sw, doc);
117116

118-
sw.Flush();
119-
return ms.ToArray();
120-
}
117+
sw.Flush();
118+
return ms.ToArray();
121119
}
122120
catch (Exception ex)
123121
{

src/MicroBatchFramework/IBatchInterceptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface IBatchInterceptor
3030
public class NullBatchInterceptor : IBatchInterceptor
3131
{
3232
public static readonly IBatchInterceptor Default = new NullBatchInterceptor();
33-
private readonly ValueTask Empty = default(ValueTask);
33+
private readonly ValueTask Empty = default;
3434

3535
public ValueTask OnBatchEngineBeginAsync(IServiceProvider serviceProvider, ILogger<BatchEngine> logger)
3636
{

0 commit comments

Comments
 (0)