大量后端代码格式化

This commit is contained in:
SunCheng
2026-01-18 22:04:56 +08:00
parent 298ce03aa6
commit 4e2bf0da6c
36 changed files with 278 additions and 200 deletions

3
Common/GlobalUsings.cs Normal file
View File

@@ -0,0 +1,3 @@
global using System.Reflection;
global using System.Text.Json;
global using Microsoft.Extensions.DependencyInjection;

View File

@@ -1,7 +1,4 @@
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
namespace Common;
namespace Common;
public static class TypeExtensions
{
@@ -10,8 +7,8 @@ public static class TypeExtensions
/// </summary>
public static T? DeepClone<T>(this T source)
{
var json = System.Text.Json.JsonSerializer.Serialize(source);
return System.Text.Json.JsonSerializer.Deserialize<T>(json);
var json = JsonSerializer.Serialize(source);
return JsonSerializer.Deserialize<T>(json);
}
}
@@ -41,7 +38,7 @@ public static class ServiceExtension
private static void RegisterServices(IServiceCollection services, Assembly assembly)
{
var types = assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract);
.Where(t => t is { IsClass: true, IsAbstract: false });
foreach (var type in types)
{
@@ -71,14 +68,13 @@ public static class ServiceExtension
private static void RegisterRepositories(IServiceCollection services, Assembly assembly)
{
var types = assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract);
.Where(t => t is { IsClass: true, IsAbstract: false });
foreach (var type in types)
{
var interfaces = type.GetInterfaces()
.Where(i => i.Name.StartsWith("I")
&& i.Namespace == "Repository"
&& !i.IsGenericType); // 排除泛型接口如 IBaseRepository<T>
&& i is { Namespace: "Repository", IsGenericType: false }); // 排除泛型接口如 IBaseRepository<T>
foreach (var @interface in interfaces)
{