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

XFEExtension

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

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

XFEstudio/XFEExtension

提升健壮性与现代化,新增空节点与停止对话方法

- FileStream 读取方法由 ReadAsync 改为 ReadExactlyAsync,提升准确性 - StringExtension 中 X/XL 方法优化 null 处理,增强健壮性 - SplitAndKeepDelimiter 方法使用集合表达式简化代码 - MemorableXFEChatGPT 新增 StopChat 静态方法,仅流式模式有效 - 项目版本号升级至 3.3.14 - QueryableJsonNode 新增静态空节点属性 Empty - GetList 和 GetList<T> 方法用集合表达式替换 ToList() - SubObjectsBase 构造函数支持 objectInfoList 为 null,提升健壮性

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

代码差异

6 个文件 +36 -15
Modified XFEExtension.NetCore/FileExtension/FileExtension.cs +1 -1
@@ -239,7 +239,7 @@ public static class FileExtension
239 239 long seekPosition = endPosition;
240 240 fileStream.Seek(startPosition, SeekOrigin.Begin);
241 241 byte[] buffer = new byte[endPosition - startPosition];
242 await fileStream.ReadAsync(buffer.AsMemory(0, (int)(endPosition - startPosition)));
242 await fileStream.ReadExactlyAsync(buffer.AsMemory(0, (int)(endPosition - startPosition)));
243 243 for (int i = buffer.Length - 1; i >= 0; i--)
244 244 {
245 245 if (buffer[i] != 0)
Modified XFEExtension.NetCore/StringExtension/StringExtension.cs +10 -4
@@ -267,7 +267,10 @@ public static partial class StringExtension
267 267 /// <param name="onlyPublic"></param>
268 268 public static string? X(this object? obj, bool onlyProperty = true, bool onlyPublic = true, string remarkName = "分析对象")
269 269 {
270 var result = XFEConverter.GetObjectInfo(StringConverter.ObjectAnalyzer, remarkName, ObjectPlace.Main, 0, [obj], obj?.GetType(), obj, onlyProperty, onlyPublic).OutPutObject();
270 var fatherList = new List<object>();
271 if (obj is not null)
272 fatherList.Add(obj);
273 var result = XFEConverter.GetObjectInfo(StringConverter.ObjectAnalyzer, remarkName, ObjectPlace.Main, 0, fatherList, obj?.GetType(), obj, onlyProperty, onlyPublic).OutPutObject();
271 274 Console.WriteLine(result);
272 275 return result;
273 276 }
@@ -281,7 +284,10 @@ public static partial class StringExtension
281 284 /// <param name="onlyPublic"></param>
282 285 public static string XL(this object? obj, string remarkName = "分析对象", bool onlyProperty = true, bool onlyPublic = true)
283 286 {
284 var result = XFEConverter.GetObjectInfo(StringConverter.ObjectAnalyzer, remarkName, ObjectPlace.Main, 0, [obj], obj?.GetType(), obj, onlyProperty, onlyPublic).OutPutObject();
287 var fatherList = new List<object>();
288 if (obj is not null)
289 fatherList.Add(obj);
290 var result = XFEConverter.GetObjectInfo(StringConverter.ObjectAnalyzer, remarkName, ObjectPlace.Main, 0, fatherList, obj?.GetType(), obj, onlyProperty, onlyPublic).OutPutObject();
285 291 Trace.WriteLine(result);
286 292 return result;
287 293 }
@@ -387,7 +393,7 @@ public static partial class StringExtension
387 393 /// <returns>分割后的带分割器字符串数组</returns>
388 394 public static string[] SplitAndKeepDelimiter(this string str, string delimiter, bool removeEmptyString)
389 395 {
390 return SplitAndKeepDelimiter(str, new string[] { delimiter }, removeEmptyString);
396 return SplitAndKeepDelimiter(str, [delimiter], removeEmptyString);
391 397 }
392 398 /// <summary>
393 399 /// 返回包含分割器的字符串
@@ -397,7 +403,7 @@ public static partial class StringExtension
397 403 /// <returns>分割后的带分割器字符串数组</returns>
398 404 public static string[] SplitAndKeepDelimiter(this string str, string delimiter)
399 405 {
400 return SplitAndKeepDelimiter(str, new string[] { delimiter }, true);
406 return SplitAndKeepDelimiter(str, [delimiter], true);
401 407 }
402 408 /// <summary>
403 409 /// 返回包含分割器的字符串
Modified XFEExtension.NetCore/XFEChatGPT/MemorableXFEChatGPT.cs +5 -1
@@ -353,8 +353,12 @@ public class MemorableXFEChatGPT : XFEChatGPTBase
353 353 }
354 354 #endregion
355 355 #region 停止对话
356
356 357 //TODO:
357 public void StopChat()
358 /// <summary>
359 /// 停止对话(仅在流式输出模式下有效,非流式输出模式下调用该方法将不会有任何效果)
360 /// </summary>
361 public static void StopChat()
358 362 {
359 363
360 364 }
Modified XFEExtension.NetCore/XFEExtension.NetCore.csproj +11 -4
@@ -5,7 +5,7 @@
5 5 <ImplicitUsings>enable</ImplicitUsings>
6 6 <Nullable>enable</Nullable>
7 7 <GenerateDocumentationFile>True</GenerateDocumentationFile>
8 <Version>3.3.13</Version>
8 <Version>3.3.14</Version>
9 9 <Title>XFEExtension</Title>
10 10 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension</RepositoryUrl>
11 11 <AnalysisLevel>latest</AnalysisLevel>
@@ -20,10 +20,17 @@
20 20 <PackageTags>XFE;拓展;GPT;Server;服务器;测试;XFEExtension</PackageTags>
21 21 <PackageReleaseNotes>
22 22 ## 调整
23
24 支持 QueryableJsonNode 到 string? 的隐式转换
25 23
26 升级项目版本号至 3.3.13,优化 QueryableJsonNode 到 string 的隐式转换操作符,支持可空类型并在节点为空时返回 null。同时在 QueryableJsonNode.cs 顶部增加了必要的 using 引用。
24 提升健壮性与现代化,新增空节点与停止对话方法
25
26 - FileStream 读取方法由 ReadAsync 改为 ReadExactlyAsync,提升准确性
27 - StringExtension 中 X/XL 方法优化 null 处理,增强健壮性
28 - SplitAndKeepDelimiter 方法使用集合表达式简化代码
29 - MemorableXFEChatGPT 新增 StopChat 静态方法,仅流式模式有效
30 - 项目版本号升级至 3.3.14
31 - QueryableJsonNode 新增静态空节点属性 Empty
32 - GetList 和 GetList`T` 方法用集合表达式替换 ToList()
33 - SubObjectsBase 构造函数支持 objectInfoList 为 null,提升健壮性
27 34
28 35 ## 新增
29 36
Modified XFEExtension.NetCore/XFETransform/JsonConverter/QueryableJsonNode.cs +6 -2
@@ -8,6 +8,10 @@ namespace XFEExtension.NetCore.XFETransform.JsonConverter;
8 8 /// <param name="jsonNode"></param>
9 9 public class QueryableJsonNode(JsonNode jsonNode) : INodeBase, IQueryableJsonNode
10 10 {
11 /// <summary>
12 /// 空节点
13 /// </summary>
14 public static readonly QueryableJsonNode Empty = new(new());
11 15 ///<inheritdoc/>
12 16 public QueryableJsonNode? this[params string[] nodeProperties] => OriginalNode is JsonComplexPropertyNode complexPropertyNode ? complexPropertyNode[nodeProperties] : throw new InvalidOperationException("该节点为简单节点,无法继续查找");
13 17 /// <summary>
@@ -70,14 +74,14 @@ public class QueryableJsonNode(JsonNode jsonNode) : INodeBase, IQueryableJsonNod
70 74 /// </summary>
71 75 /// <returns></returns>
72 76 /// <exception cref="NullReferenceException"></exception>
73 public List<string> GetList() => OriginalNode is JsonComplexPropertyNode jsonComplexPropertyNode ? jsonComplexPropertyNode.DescendingNodes.Select(node => node is IValueNode valueNode ? valueNode.Value : null!).ToList() : throw new NullReferenceException();
77 public List<string> GetList() => OriginalNode is JsonComplexPropertyNode jsonComplexPropertyNode ? [.. jsonComplexPropertyNode.DescendingNodes.Select(node => node is IValueNode valueNode ? valueNode.Value : null!)] : throw new NullReferenceException();
74 78 /// <summary>
75 79 /// 使用指定类型获取列表
76 80 /// </summary>
77 81 /// <typeparam name="T">指定类型</typeparam>
78 82 /// <returns></returns>
79 83 /// <exception cref="NullReferenceException"></exception>
80 public List<T> GetList<T>() => OriginalNode is JsonComplexPropertyNode jsonComplexPropertyNode ? jsonComplexPropertyNode.DescendingNodes.Select(node => node is IValueNode valueNode ? (T)GetValueByValueType(valueNode.Value, valueNode.ValueType)! : default!).ToList() : throw new NullReferenceException();
84 public List<T> GetList<T>() => OriginalNode is JsonComplexPropertyNode jsonComplexPropertyNode ? [.. jsonComplexPropertyNode.DescendingNodes.Select(node => node is IValueNode valueNode ? (T)GetValueByValueType(valueNode.Value, valueNode.ValueType)! : default!)] : throw new NullReferenceException();
81 85 /// <summary>
82 86 /// 对列表内对象属性值进行打包
83 87 /// </summary>
Modified XFEExtension.NetCore/XFETransform/ObjectInfoAnalyzer/SubObjectsBase.cs +3 -3
@@ -7,11 +7,11 @@ internal abstract class SubObjectsBase : ISubObjects
7 7
8 8 protected readonly List<IObjectInfo> objectInfoList;
9 9
10 protected SubObjectsBase(List<IObjectInfo> objectInfoList, IObjectInfo parent)
10 protected SubObjectsBase(List<IObjectInfo>? objectInfoList, IObjectInfo parent)
11 11 {
12 this.objectInfoList = objectInfoList;
12 this.objectInfoList = objectInfoList ?? [];
13 13 Parent = parent;
14 objectInfoList.ForEach(objectInfo => objectInfo.Parent = parent);
14 objectInfoList?.ForEach(objectInfo => objectInfo.Parent = parent);
15 15 }
16 16
17 17 public IObjectInfo this[int index] { get => objectInfoList[index]; set => objectInfoList[index] = value; }