Apply Rider recommendations.

This commit is contained in:
2023-05-22 01:34:33 +02:00
parent 216b4e7708
commit a3299b3daf
7 changed files with 9 additions and 19 deletions

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.IO;
using System.Text; using System.Text;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using VAR.Json; using VAR.Json;
@@ -38,11 +37,7 @@ namespace VAR.WebFormsCore.Code
context.Response.Body.WriteAsync(byteObject).GetAwaiter().GetResult(); context.Response.Body.WriteAsync(byteObject).GetAwaiter().GetResult();
} }
public static void SafeSet(this IHeaderDictionary header, string key, string value) public static void SafeSet(this IHeaderDictionary header, string key, string value) { header[key] = value; }
{
if (header.ContainsKey(key)) { header[key] = value; }
else { header.Add(key, value); }
}
public static void SafeDel(this IHeaderDictionary header, string key) public static void SafeDel(this IHeaderDictionary header, string key)
{ {

View File

@@ -22,8 +22,7 @@ namespace VAR.WebFormsCore.Code
x => x =>
x.IsAbstract == false && x.IsAbstract == false &&
x.IsInterface == false && x.IsInterface == false &&
iGlobalConfig.IsAssignableFrom(x) && iGlobalConfig.IsAssignableFrom(x)
true
); );
_globalConfig = ObjectActivator.CreateInstance(foundGlobalConfig) as IGlobalConfig; _globalConfig = ObjectActivator.CreateInstance(foundGlobalConfig) as IGlobalConfig;

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using VAR.WebFormsCore.Pages; using VAR.WebFormsCore.Pages;

View File

@@ -85,12 +85,11 @@ namespace VAR.WebFormsCore.Code
{ {
if (string.IsNullOrEmpty(typeName)) { return null; } if (string.IsNullOrEmpty(typeName)) { return null; }
Type type = null; Type type;
lock (Handlers) lock (Handlers)
{ {
if (Handlers.ContainsKey(typeName)) if (Handlers.TryGetValue(typeName, out type))
{ {
type = Handlers[typeName];
IHttpHandler handler = ObjectActivator.CreateInstance(type) as IHttpHandler; IHttpHandler handler = ObjectActivator.CreateInstance(type) as IHttpHandler;
return handler; return handler;
} }
@@ -135,7 +134,7 @@ namespace VAR.WebFormsCore.Code
{ {
lock (Handlers) lock (Handlers)
{ {
if (Handlers.ContainsKey(typeName) == false) { Handlers.Add(typeName, type); } Handlers.TryAdd(typeName, type);
} }
} }

View File

@@ -12,7 +12,7 @@ namespace VAR.WebFormsCore.Code
{ {
lock (Creators) lock (Creators)
{ {
if (Creators.ContainsKey(type)) { return Creators[type]; } if (Creators.TryGetValue(type, out var creator)) { return creator; }
NewExpression newExp = Expression.New(type); NewExpression newExp = Expression.New(type);
LambdaExpression lambda = Expression.Lambda(typeof(Func<object>), newExp); LambdaExpression lambda = Expression.Lambda(typeof(Func<object>), newExp);

View File

@@ -71,8 +71,7 @@ namespace VAR.WebFormsCore.Code
ch == '!' || ch == '!' ||
ch == '*' || ch == '*' ||
ch == '(' || ch == '(' ||
ch == ')' || ch == ')') { return true; }
false) { return true; }
return false; return false;
} }

View File

@@ -71,14 +71,13 @@ namespace VAR.WebFormsCore.Code
public static async void ResponseStaticFile(HttpContext context, string filePath) public static async void ResponseStaticFile(HttpContext context, string filePath)
{ {
string extension = Path.GetExtension(filePath).ToLower(); string extension = Path.GetExtension(filePath).ToLower();
string contentType = null; MimeTypeByExtension.TryGetValue(extension, out string contentType);
if (MimeTypeByExtension.ContainsKey(extension)) { contentType = MimeTypeByExtension[extension]; }
if (string.IsNullOrEmpty(contentType) == false) { context.Response.ContentType = contentType; } if (string.IsNullOrEmpty(contentType) == false) { context.Response.ContentType = contentType; }
context.Response.PrepareCacheableResponse(); context.Response.PrepareCacheableResponse();
byte[] fileData = File.ReadAllBytes(filePath); byte[] fileData = await File.ReadAllBytesAsync(filePath);
await context.Response.Body.WriteAsync(fileData); await context.Response.Body.WriteAsync(fileData);
} }
} }