Skip to content

Commit

Permalink
PropertyNameCaseInsensitive = true
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Dec 13, 2022
1 parent 4f9e659 commit b68e4e0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
9 changes: 8 additions & 1 deletion src/Common.CoreLib/Serializable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ public static Task SMPAsync(Type type, Stream stream, object value, Cancellation

#endregion

// https://learn.microsoft.com/zh-cn/dotnet/standard/serialization/system-text-json/character-casing#case-insensitive-property-matching

static readonly SJsonSerializerOptions S_options = new()
{
PropertyNameCaseInsensitive = true,
};

#region Deserialize(反序列化)

/// <summary>
Expand All @@ -204,7 +211,7 @@ public static T DJSON<T>(JsonImplType implType, string value)
{
return implType switch
{
JsonImplType.SystemTextJson => SJsonSerializer.Deserialize<T>(value),
JsonImplType.SystemTextJson => SJsonSerializer.Deserialize<T>(value, S_options),
_ =>
#if NOT_NJSON
throw new NotSupportedException(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
using System.Globalization;
using System.IO;
using System.Linq;
#if WINDOWS
using System.Management;
#endif
using System.Net;
using System.Net.Http;
using System.Runtime.Versioning;
Expand Down Expand Up @@ -147,38 +149,36 @@ public int GetSteamProcessPid()

public bool IsSteamChinaLauncher()
{
if (OperatingSystem2.IsWindows())
#if WINDOWS
var process = GetSteamProces();
if (process != null)
{
var process = GetSteamProces();

if (process != null)
try
{
try
{
return GetCommandLineArgsCore().Contains("-steamchina", StringComparison.OrdinalIgnoreCase);
}
catch (Win32Exception ex) when ((uint)ex.ErrorCode == 0x80004005)
{
// 没有对该进程的安全访问权限。
return false;
}
catch (InvalidOperationException)
{
// 进程已退出。
return false;
}
return GetCommandLineArgsCore().Contains("-steamchina", StringComparison.OrdinalIgnoreCase);
}
string GetCommandLineArgsCore()
catch (Win32Exception ex) when ((uint)ex.ErrorCode == 0x80004005)
{
using (var searcher = new ManagementObjectSearcher(
"SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
using (var objects = searcher.Get())
{
var @object = objects.Cast<ManagementBaseObject>().SingleOrDefault();
return @object?["CommandLine"]?.ToString() ?? "";
}
// 没有对该进程的安全访问权限。
return false;
}
catch (InvalidOperationException)
{
// 进程已退出。
return false;
}
}
string GetCommandLineArgsCore()
{
using (var searcher = new ManagementObjectSearcher(
"SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
using (var objects = searcher.Get())
{
var @object = objects.Cast<ManagementBaseObject>().SingleOrDefault();
return @object?["CommandLine"]?.ToString() ?? "";
}
}
#endif
return false;
}

Expand Down

0 comments on commit b68e4e0

Please sign in to comment.