XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension

新增JsonNode操作符

0918fe4
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

3 个文件 +29 -5
Modified XFEExtension.NetCore.Test/Program.cs +7 -0
@@ -6,6 +6,13 @@ internal class Program
6 6 private static void Main(string[] args)
7 7 {
8 8 QueryableJsonNode jsonNode = @"C:\Users\XFEstudio\Desktop\测试\Bilibili解析失败.txt".ReadOut()!;
9 var value = jsonNode["test1"]["subObject"]["testText"];
10 value = jsonNode["test1"]?["subObject"]?["testText"] ?? QueryableJsonNode.Empty;
11 value = jsonNode > "test1" > "subObject" > "testText";
12 value = jsonNode < "test1" < "subObject" < "testText";
13 value = jsonNode < "test1" > "subObject" < "testText" > "myProperty";
14 value = jsonNode - "test1" - "subObject" - "testText" - "myProperty";
15 value = jsonNode / "test1" / "subObject" / "testText" / "myProperty";
9 16 //var testClass = new TestClass("123", "sda", 12);
10 17 //testClass.ToJson().CW();
11 18 }
Modified XFEExtension.NetCore/XFEExtension.NetCore.csproj +3 -5
@@ -5,7 +5,7 @@
5 5 <ImplicitUsings>enable</ImplicitUsings>
6 6 <Nullable>enable</Nullable>
7 7 <GenerateDocumentationFile>True</GenerateDocumentationFile>
8 <Version>4.1.0</Version>
8 <Version>4.2.0</Version>
9 9 <Title>XFEExtension</Title>
10 10 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension</RepositoryUrl>
11 11 <AnalysisLevel>latest</AnalysisLevel>
@@ -21,13 +21,11 @@
21 21 <PackageReleaseNotes>
22 22 ## 调整
23 23
24 重构字符串扩展属性并升级版本号
25
26 将 IsNullOrEmpty 和 IsNullOrWhiteSpace 从方法改为属性,移除 IsWhiteSpace 属性。同时将项目版本号从 4.0.4 升级到 4.1.0。
24
27 25
28 26 ## 新增
29 27
30
28 新增JsonNode操作符
31 29
32 30 ## 严重
33 31
Modified XFEExtension.NetCore/XFETransform/JsonConverter/QueryableJsonNode.cs +19 -0
@@ -107,6 +107,25 @@ public class QueryableJsonNode(JsonNode jsonNode) : INodeBase, IQueryableJsonNod
107 107 [return: NotNullIfNotNull(nameof(jsonString))]
108 108 public static implicit operator QueryableJsonNode?(string? jsonString) => jsonString is null ? null : new(new JsonNodeConverter(jsonString).ConvertToJsonNode());
109 109 /// <summary>
110 /// Retrieves the child node at the specified path from the given queryable JSON node.
111 /// </summary>
112 /// <remarks>This operator provides a convenient way to access nested nodes within a JSON structure using
113 /// a path string. The path format and supported syntax depend on the implementation of the indexer.</remarks>
114 /// <param name="queryableJsonNode">The source JSON node to query. Can be null.</param>
115 /// <param name="nodePath">The path to the child node to retrieve. Must not be null.</param>
116 /// <returns>The child node at the specified path, or null if the path does not exist or the source node is null.</returns>
117 public static QueryableJsonNode? operator >(QueryableJsonNode? queryableJsonNode, string nodePath) => queryableJsonNode?[nodePath];
118 /// <summary>
119 /// Retrieves the child node at the specified path from the given queryable JSON node.
120 /// </summary>
121 /// <remarks>This operator provides a convenient syntax for accessing child nodes within a JSON structure
122 /// using a string path. If the specified path does not exist, the result is null.</remarks>
123 /// <param name="queryableJsonNode">The parent JSON node to query. Can be null.</param>
124 /// <param name="nodePath">The path of the child node to retrieve. Must not be null.</param>
125 /// <returns>A QueryableJsonNode representing the child node at the specified path, or null if the parent node is null or the
126 /// path does not exist.</returns>
127 public static QueryableJsonNode? operator <(QueryableJsonNode? queryableJsonNode, string nodePath) => queryableJsonNode?[nodePath];
128 /// <summary>
110 129 /// 隐式将Json字符串转换为节点值
111 130 /// </summary>
112 131 /// <param name="queryableJsonNode"></param>