😎代码优化

This commit is contained in:
zuohuaijun 2025-03-02 17:20:37 +08:00
parent 18e64c524e
commit ac3d0bb6f6
8 changed files with 12 additions and 22 deletions

View File

@ -5,7 +5,6 @@
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using NewLife.Caching.Queues; using NewLife.Caching.Queues;
using Newtonsoft.Json;
using System.Threading.Channels; using System.Threading.Channels;
namespace Admin.NET.Core; namespace Admin.NET.Core;
@ -85,7 +84,7 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable
private async Task OnConsumeBroadcast(string source, Message message, CancellationToken token) private async Task OnConsumeBroadcast(string source, Message message, CancellationToken token)
{ {
ChannelEventSource ces = JsonConvert.DeserializeObject<ChannelEventSource>(source); ChannelEventSource ces = JSON.Deserialize<ChannelEventSource>(source);
await ConsumeChannelEventSourceAsync(ces, token); await ConsumeChannelEventSourceAsync(ces, token);
} }
@ -121,7 +120,7 @@ public sealed class RedisEventSourceStorer : IEventSourceStorer, IDisposable
{ {
if (source.EventId != null && source.EventId.StartsWith("broadcast:")) if (source.EventId != null && source.EventId.StartsWith("broadcast:"))
{ {
string str = JsonConvert.SerializeObject(source); var str = JSON.Serialize(source);
_queueBroadcast.Add(str); _queueBroadcast.Add(str);
} }
else else

View File

@ -4,8 +4,6 @@
// //
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using System.Text.Json;
namespace Admin.NET.Core; namespace Admin.NET.Core;
/// <summary> /// <summary>
@ -271,7 +269,7 @@ public static partial class ObjectExtension
/// <returns></returns> /// <returns></returns>
public static T DeepCopy<T>(this T obj) public static T DeepCopy<T>(this T obj)
{ {
var json = JsonSerializer.Serialize(obj); var json = JSON.Serialize(obj);
return JsonSerializer.Deserialize<T>(json); return JSON.Deserialize<T>(json);
} }
} }

View File

@ -17,6 +17,7 @@ global using Furion.FriendlyException;
global using Furion.HttpRemote; global using Furion.HttpRemote;
global using Furion.JsonSerialization; global using Furion.JsonSerialization;
global using Furion.Logging; global using Furion.Logging;
global using Furion.Logging.Extensions;
global using Furion.Schedule; global using Furion.Schedule;
global using Furion.UnifyResult; global using Furion.UnifyResult;
global using Furion.ViewEngine; global using Furion.ViewEngine;

View File

@ -4,8 +4,6 @@
// //
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Newtonsoft.Json;
namespace Admin.NET.Core.Service; namespace Admin.NET.Core.Service;
/// <summary> /// <summary>
@ -145,7 +143,7 @@ public class SysCacheService : IDynamicApiController, ISingleton
private static string KeySingle(object t) private static string KeySingle(object t)
{ {
return t.GetType().IsClass && !t.GetType().IsPrimitive ? JsonConvert.SerializeObject(t) : t.ToString(); return t.GetType().IsClass && !t.GetType().IsPrimitive ? JSON.Serialize(t) : t.ToString();
} }
/// <summary> /// <summary>

View File

@ -5,7 +5,6 @@
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Admin.NET.Core; using Admin.NET.Core;
using Newtonsoft.Json.Converters;
using Npgsql; using Npgsql;
namespace Admin.NET.Core.Service; namespace Admin.NET.Core.Service;
@ -473,7 +472,7 @@ public class SysDatabaseService : IDynamicApiController, ITransient
for (var j = i; j > 0; j--) propertyList[j] = propertyList[j - 1]; for (var j = i; j > 0; j--) propertyList[j] = propertyList[j - 1];
propertyList[0] = temp; propertyList[0] = temp;
} }
var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }; // var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
// var recordList = JsonConvert.SerializeObject(records, Formatting.Indented, timeConverter); // var recordList = JsonConvert.SerializeObject(records, Formatting.Indented, timeConverter);
// 拼接种子数据 // 拼接种子数据

View File

@ -4,10 +4,6 @@
// //
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Furion.Logging.Extensions;
using NewLife;
using Newtonsoft.Json;
namespace Admin.NET.Core.Service; namespace Admin.NET.Core.Service;
/// <summary> /// <summary>
@ -172,7 +168,7 @@ public class SysWechatPayService : IDynamicApiController, ITransient
var response = await _wechatTenpayClient.ExecuteCreatePayTransactionNativeAsync(request); var response = await _wechatTenpayClient.ExecuteCreatePayTransactionNativeAsync(request);
if (!response.IsSuccessful()) if (!response.IsSuccessful())
{ {
JsonConvert.SerializeObject(response).LogInformation(); JSON.Serialize(response).LogInformation();
throw Oops.Oh(response.ErrorMessage); throw Oops.Oh(response.ErrorMessage);
} }
// 保存订单信息 // 保存订单信息

View File

@ -45,8 +45,8 @@ public partial class WechatApiClientFactory : ISingleton
{ {
JsonSerializerSettings jsonSerializerSettings = NewtonsoftJsonSerializer.GetDefaultSerializerSettings(); JsonSerializerSettings jsonSerializerSettings = NewtonsoftJsonSerializer.GetDefaultSerializerSettings();
jsonSerializerSettings.Formatting = Formatting.Indented; jsonSerializerSettings.Formatting = Formatting.Indented;
config.JsonSerializer = new NewtonsoftJsonSerializer(jsonSerializerSettings); // 指定 System.Text.Json JSON序列化 config.JsonSerializer = new NewtonsoftJsonSerializer(jsonSerializerSettings); // 指定 Newtonsoft.Json JSON序列化
// config.JsonSerializer = new SystemTextJsonSerializer(jsonSerializerOptions); // 指定 Newtonsoft.Json JSON序列化 // config.JsonSerializer = new SystemTextJsonSerializer(jsonSerializerSettings); // 指定 System.Text.Json JSON序列化
}); });
return client; return client;
@ -75,8 +75,8 @@ public partial class WechatApiClientFactory : ISingleton
{ {
JsonSerializerSettings jsonSerializerSettings = NewtonsoftJsonSerializer.GetDefaultSerializerSettings(); JsonSerializerSettings jsonSerializerSettings = NewtonsoftJsonSerializer.GetDefaultSerializerSettings();
jsonSerializerSettings.Formatting = Formatting.Indented; jsonSerializerSettings.Formatting = Formatting.Indented;
config.JsonSerializer = new NewtonsoftJsonSerializer(jsonSerializerSettings); // 指定 System.Text.Json JSON序列化 config.JsonSerializer = new NewtonsoftJsonSerializer(jsonSerializerSettings); // 指定 Newtonsoft.Json JSON序列化
// config.JsonSerializer = new SystemTextJsonSerializer(jsonSerializerOptions); // 指定 Newtonsoft.Json JSON序列化 // config.JsonSerializer = new SystemTextJsonSerializer(jsonSerializerSettings); // 指定 System.Text.Json JSON序列化
}); });
return client; return client;

View File

@ -4,7 +4,6 @@
// //
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任! // 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
using Furion.Logging.Extensions;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Newtonsoft.Json; using Newtonsoft.Json;
using StackExchange.Redis; using StackExchange.Redis;