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

View File

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

View File

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

View File

@@ -85,12 +85,11 @@ namespace VAR.WebFormsCore.Code
{
if (string.IsNullOrEmpty(typeName)) { return null; }
Type type = null;
Type type;
lock (Handlers)
{
if (Handlers.ContainsKey(typeName))
if (Handlers.TryGetValue(typeName, out type))
{
type = Handlers[typeName];
IHttpHandler handler = ObjectActivator.CreateInstance(type) as IHttpHandler;
return handler;
}
@@ -135,7 +134,7 @@ namespace VAR.WebFormsCore.Code
{
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)
{
if (Creators.ContainsKey(type)) { return Creators[type]; }
if (Creators.TryGetValue(type, out var creator)) { return creator; }
NewExpression newExp = Expression.New(type);
LambdaExpression lambda = Expression.Lambda(typeof(Func<object>), newExp);

View File

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

View File

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