From 41208a5d7f63ad595ec985d3616fbce2c9bdc4d0 Mon Sep 17 00:00:00 2001 From: tk Date: Tue, 2 Jul 2024 11:02:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20=E6=96=B0=E5=A2=9Estring?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E5=87=BD=E6=95=B0=20IsJsonString?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.props | 2 +- NSExt.sln.DotSettings | 131 +++++++----------- build/code.quality.props | 6 +- src/backend/NSExt.Tests/AllTests.cs | 19 +++ src/backend/NSExt.Tests/NSExt.Tests.csproj | 7 +- .../NSExt/Extensions/StringExtensions.cs | 20 +++ 6 files changed, 95 insertions(+), 90 deletions(-) create mode 100644 src/backend/NSExt.Tests/AllTests.cs diff --git a/Directory.Build.props b/Directory.Build.props index b2ad2a4..5d1b5a8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -26,7 +26,7 @@ $(AssemblyName) - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/NSExt.sln.DotSettings b/NSExt.sln.DotSettings index ea9fc25..0913323 100644 --- a/NSExt.sln.DotSettings +++ b/NSExt.sln.DotSettings @@ -1,58 +1,38 @@ - - Inherit - True - True - DO_NOT_SHOW - HINT - DO_NOT_SHOW - DO_NOT_SHOW - NEVER - NEVER - NEVER - NEVER - ID - IOS - IP - UI - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /> - - True - True - True - True - True - 1 - 1 + + + True + Inherit + + + True OFF - HINT + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + HINT + DO_NOT_SHOW + DO_NOT_SHOW + + + 1 + 1 Required - Required - Required + Required + Required Required - <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> - <Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /> - <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + NEVER + NEVER + NEVER + NEVER + <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"><ElementKinds><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Private" Description="Constant fields (private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Constant fields (not private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"><ElementKinds><Kind Name="NAMESPACE" /><Kind Name="CLASS" /><Kind Name="STRUCT" /><Kind Name="ENUM" /><Kind Name="DELEGATE" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></Policy> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Static readonly fields (not private)"><ElementKinds><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></Policy> + <?xml version="1.0" encoding="utf-16"?> <Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"> <TypePattern> @@ -93,36 +73,21 @@ </Entry> </TypePattern> </Patterns> - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True - True + + + True + True + True + True + True + + + True + + + True + True + True + True \ No newline at end of file diff --git a/build/code.quality.props b/build/code.quality.props index c9025f2..5e41197 100644 --- a/build/code.quality.props +++ b/build/code.quality.props @@ -15,15 +15,15 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/backend/NSExt.Tests/AllTests.cs b/src/backend/NSExt.Tests/AllTests.cs new file mode 100644 index 0000000..eeddbeb --- /dev/null +++ b/src/backend/NSExt.Tests/AllTests.cs @@ -0,0 +1,19 @@ +using NSExt.Extensions; +using Xunit; + +namespace NSExt; + +/// +/// 所有测试用例 +/// +public class AllTests +{ + /// + /// IsJsonString + /// + [Fact] + public void IsJsonString() + { + Assert.True("{\"a\":\"b\"}".IsJsonString()); + } +} \ No newline at end of file diff --git a/src/backend/NSExt.Tests/NSExt.Tests.csproj b/src/backend/NSExt.Tests/NSExt.Tests.csproj index 571955e..b14ac29 100644 --- a/src/backend/NSExt.Tests/NSExt.Tests.csproj +++ b/src/backend/NSExt.Tests/NSExt.Tests.csproj @@ -1,11 +1,12 @@ - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/backend/NSExt/Extensions/StringExtensions.cs b/src/backend/NSExt/Extensions/StringExtensions.cs index 80c49fe..1b3a3c9 100644 --- a/src/backend/NSExt/Extensions/StringExtensions.cs +++ b/src/backend/NSExt/Extensions/StringExtensions.cs @@ -358,6 +358,26 @@ public static class StringExtensions return lastEqualSignPos == me.Length - 1 && me[firstEqualSignPos..lastEqualSignPos].All(x => x == '='); } + /// + /// 是否json字符串 + /// + /// me + public static bool IsJsonString(this string me) + { + if (me.NullOrEmpty()) { + return false; + } + + try { + _ = JsonDocument.Parse(me); + } + catch { + return false; + } + + return true; + } + /// /// 中文姓名打马赛克 ///