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

XFEExtension

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

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

XFEstudio/XFEExtension

现在,对象分析已使用依赖注入

ba7dcc0
XFE工作室室长 <xfe18827675401@126.com>
提交于

代码差异

13 个文件 +173 -142
Modified XFEExtension.NetCore.Analyzer.Test/Program.cs +5 -22
@@ -1,32 +1,15 @@
1 using XFEExtension.NetCore.FileExtension;
2 using XFEExtension.NetCore.WebExtension;
1 using XFEExtension.NetCore.StringExtension;
3 2
4 3 namespace XFEExtension.NetCore.Analyzer.Test;
5 4
6 5 internal class Program
7 6 {
8 public static async Task Main(string[] args)
7 public static void Main(string[] args)
9 8 {
10 var xFEDownloader = new XFEDownloader()
9 var testClass = new TestClass("测试名称", "测试描述哈哈", 59)
11 10 {
12 DownloadUrl = "https://www.xfegzs.com/com.xfegzs.xccchatroom.apk",
13 SavePath = @"D:\work\C#\OtherProject\XUnitConsole\XUnitConsole\bin\Debug\net8.0\com.xfegzs.xccchatroom.apk"
11 Tags = [["123", "321"], ["1234567", "7654321"]]
14 12 };
15 xFEDownloader.BufferDownloaded += XFEDownloader_BufferDownloaded;
16 var task = Task.Run(async () =>
17 {
18 await Task.Delay(5000);
19 xFEDownloader.Pause();
20 await Console.Out.WriteLineAsync("已暂停,将于10秒后开始");
21 await Task.Delay(10000);
22 await xFEDownloader.Continue();
23 });
24 await xFEDownloader.Download();
25 await task;
26 }
27
28 private static void XFEDownloader_BufferDownloaded(XFEDownloader sender, FileDownloadedEventArgs e)
29 {
30 Console.WriteLine($"{e.DownloadedBufferSize.FileSize()} /{((long)e.TotalBufferSize!).FileSize()}");
13 testClass.X();
31 14 }
32 15 }
Modified XFEExtension.NetCore/StringExtension/StringExtension.cs +2 -2
@@ -262,7 +262,7 @@ public static partial class StringExtension
262 262 /// <param name="remarkName">对象别名</param>
263 263 /// <param name="onlyProperty"></param>
264 264 /// <param name="onlyPublic"></param>
265 public static void X(this object? obj, string remarkName = "分析对象", bool onlyProperty = true, bool onlyPublic = true) => Console.WriteLine(XFEConverter.GetObjectInfo(remarkName, ObjectPlace.Main, 0, obj?.GetType(), obj, onlyProperty, onlyPublic).OutPut());
265 public static void X(this object? obj, string remarkName = "分析对象", bool onlyProperty = true, bool onlyPublic = true) => Console.WriteLine(XFEConverter.GetObjectInfo(new ObjectAnalyzer(), remarkName, ObjectPlace.Main, 0, obj?.GetType(), obj, onlyProperty, onlyPublic).OutPutObject());
266 266 /// <summary>
267 267 /// 分析对象并输出到跟踪输出
268 268 /// </summary>
@@ -270,7 +270,7 @@ public static partial class StringExtension
270 270 /// <param name="remarkName">对象别名</param>
271 271 /// <param name="onlyProperty"></param>
272 272 /// <param name="onlyPublic"></param>
273 public static void XL(this object? obj, string remarkName = "分析对象", bool onlyProperty = true, bool onlyPublic = true) => Trace.WriteLine(XFEConverter.GetObjectInfo(remarkName, ObjectPlace.Main, 0, obj?.GetType(), obj, onlyProperty, onlyPublic).OutPut());
273 public static void XL(this object? obj, string remarkName = "分析对象", bool onlyProperty = true, bool onlyPublic = true) => Trace.WriteLine(XFEConverter.GetObjectInfo(new ObjectAnalyzer(), remarkName, ObjectPlace.Main, 0, obj?.GetType(), obj, onlyProperty, onlyPublic).OutPutObject());
274 274 /// <summary>
275 275 /// 字符串实际显示的长度
276 276 /// </summary>
Modified XFEExtension.NetCore/XFETransform/IObjectInfo.cs +6 -5
@@ -22,9 +22,13 @@ public interface IObjectInfo
22 22 /// </summary>
23 23 ISubObjects? SubObjects { get; init; }
24 24 /// <summary>
25 /// 字符串转换器
26 /// </summary>
27 IStringConverter? StringConverter { get; init; }
28 /// <summary>
25 29 /// 对象类型
26 30 /// </summary>
27 Type Type { get; init; }
31 Type? Type { get; init; }
28 32 /// <summary>
29 33 /// 对象值
30 34 /// </summary>
@@ -37,12 +41,9 @@ public interface IObjectInfo
37 41 /// 对象层级
38 42 /// </summary>
39 43 int Layer { get; init; }
40
41 string AddObjectPlace();
42
43 44 /// <summary>
44 45 /// 输出对象信息
45 46 /// </summary>
46 47 /// <returns></returns>
47 string OutPut();
48 string OutPutObject();
48 49 }
Added XFEExtension.NetCore/XFETransform/IStringConverter.cs +14 -0
@@ -0,0 +1,14 @@
1 namespace XFEExtension.NetCore.XFETransform;
2
3 /// <summary>
4 /// 字符串转换接口
5 /// </summary>
6 public interface IStringConverter
7 {
8 /// <summary>
9 /// 输出对象信息
10 /// </summary>
11 /// <param name="objectInfo">对象信息</param>
12 /// <returns></returns>
13 string OutPutObject(IObjectInfo objectInfo);
14 }
Modified XFEExtension.NetCore/XFETransform/ISubObjects.cs +2 -3
@@ -6,8 +6,7 @@
6 6 public interface ISubObjects : IList<IObjectInfo>
7 7 {
8 8 /// <summary>
9 /// 输出子对象信息
9 /// 父类
10 10 /// </summary>
11 /// <returns></returns>
12 string OutPutSubObjects();
11 IObjectInfo Parent { get; init; }
13 12 }
Added XFEExtension.NetCore/XFETransform/ObjectAnalyzer.cs +103 -0
@@ -0,0 +1,103 @@
1 namespace XFEExtension.NetCore.XFETransform;
2
3 /// <summary>
4 /// 对象分析类
5 /// </summary>
6 public class ObjectAnalyzer : IStringConverter
7 {
8 /// <summary>
9 /// 分析对象
10 /// </summary>
11 /// <param name="objectInfo"></param>
12 /// <returns></returns>
13 public string OutPutObject(IObjectInfo objectInfo)
14 {
15 var outPutString = string.Empty;
16 if (objectInfo.IsBasicType)
17 {
18 if (objectInfo.Value is null)
19 {
20 outPutString += $"{AddObjectPlace(objectInfo)} 空对象 {objectInfo.Name}:null\n";
21 }
22 else
23 {
24 outPutString += $"{AddObjectPlace(objectInfo)} {XFEConverter.OutPutTypeName(objectInfo.Type!)} {objectInfo.Name}:{objectInfo.Value}\n";
25 }
26 }
27 else
28 {
29 if (objectInfo.Layer == 0)
30 {
31 outPutString += $"""
32 {AddObjectPlace(objectInfo)} {XFEConverter.OutPutTypeName(objectInfo.Type!)} {objectInfo.Name}
33 ┌────┬────────────────────────────
34 {(objectInfo.SubObjects is not null ? OutPutSubObjects(objectInfo.SubObjects) : "| └─空对象")}
35 └─────────────────────────────────
36
37 """;
38 }
39 else
40 {
41 if (objectInfo.SubObjects is not null)
42 outPutString += OutPutSubObjects(objectInfo.SubObjects);
43 }
44 }
45 return outPutString;
46 }
47
48 internal static string OutPutSubObjects(ISubObjects subObjects)
49 {
50 var outString = string.Empty;
51 for (int i = 0; i < subObjects.Count; i++)
52 {
53 var obj = subObjects[i];
54 var tabString = string.Empty;
55 for (int k = 0; k < obj.Layer; k++)
56 {
57 tabString += "│ ";
58 }
59 outString += tabString;
60 string? currentConnectString;
61 if (i == subObjects.Count - 1)
62 {
63 currentConnectString = "└─";
64 }
65 else
66 {
67 currentConnectString = "├─";
68 }
69 if (obj.IsBasicType)
70 {
71 outString += currentConnectString;
72 outString += obj.OutPutObject();
73 }
74 else
75 {
76 outString += $"""
77 ├─{AddObjectPlace(obj)} {XFEConverter.OutPutTypeName(obj.Type!)} {obj.Name}
78 {tabString}├────┬────────────────────────────
79 {obj.OutPutObject()}
80 {tabString}{currentConnectString}────────────────────────────────
81
82 """;
83 }
84 }
85 if (outString.Length > 0 && outString[^1] == '\n')
86 {
87 outString = outString[..^1];
88 }
89 return outString;
90 }
91
92 internal static string AddObjectPlace(IObjectInfo objectInfo) => objectInfo.ObjectPlace switch
93 {
94 ObjectPlace.Property => "[属性]",
95 ObjectPlace.Field => "[字段]",
96 ObjectPlace.Main => "[主体]",
97 ObjectPlace.Array => "[数组]",
98 ObjectPlace.List => "[列表]",
99 ObjectPlace.Enum => "[枚举]",
100 ObjectPlace.Other => "[其他]",
101 _ => string.Empty,
102 };
103 }
Modified XFEExtension.NetCore/XFETransform/ObjectInfo.cs +8 -46
@@ -6,59 +6,20 @@ internal abstract class ObjectInfo : IObjectInfo
6 6 public ObjectPlace ObjectPlace { get; init; }
7 7 public int Layer { get; init; }
8 8 public object? Value { get; init; }
9 public Type Type { get; init; }
9 public Type? Type { get; init; }
10 10 public bool IsBasicType { get; init; }
11 11 public bool IsArray { get; init; }
12 12 public ISubObjects? SubObjects { get; init; }
13 public IStringConverter? StringConverter { get; init; }
13 14
14 public string OutPut()
15 public string OutPutObject()
15 16 {
16 var outPutString = string.Empty;
17 if (IsBasicType)
18 {
19 if (Value is null)
20 {
21 outPutString += $"{AddObjectPlace()} 空对象 {Name}:null\n";
22 }
23 else
24 {
25 outPutString += $"{AddObjectPlace()} {XFEConverter.OutPutTypeName(Type)} {Name}:{Value}\n";
26 }
27 }
28 else
29 {
30 if (Layer == 0)
31 {
32 outPutString += $"""
33 {AddObjectPlace()} {XFEConverter.OutPutTypeName(Type)} {Name}
34 ┌────┬────────────────────────────
35 {SubObjects?.OutPutSubObjects()}
36 └─────────────────────────────────
37
38 """;
39 }
40 else
41 {
42 outPutString += SubObjects?.OutPutSubObjects();
43 }
44 }
45 return outPutString;
17 return StringConverter!.OutPutObject(this);
46 18 }
47 19
48 public string AddObjectPlace() => ObjectPlace switch
49 {
50 ObjectPlace.Property => "[属性]",
51 ObjectPlace.Field => "[字段]",
52 ObjectPlace.Main => "[主体]",
53 ObjectPlace.Array => "[数组]",
54 ObjectPlace.List => "[列表]",
55 ObjectPlace.Enum => "[枚举]",
56 ObjectPlace.Other => "[其他]",
57 _ => string.Empty,
58 };
59
60 public ObjectInfo(string? name, ObjectPlace objectPlace, int layer, Type type, bool isBasicType, object? value = null)
20 public ObjectInfo(IStringConverter? stringConverter, string? name, ObjectPlace objectPlace, int layer, Type? type, bool isBasicType, object? value = null)
61 21 {
22 StringConverter = stringConverter;
62 23 Name = name;
63 24 ObjectPlace = objectPlace;
64 25 Layer = layer;
@@ -67,8 +28,9 @@ internal abstract class ObjectInfo : IObjectInfo
67 28 IsArray = false;
68 29 Value = value;
69 30 }
70 public ObjectInfo(string? name, ObjectPlace objectPlace, int layer, Type type, bool isBasicType, bool isArray, object? value = null, List<IObjectInfo>? objectInfoList = null)
31 public ObjectInfo(IStringConverter? stringConverter, string? name, ObjectPlace objectPlace, int layer, Type? type, bool isBasicType, bool isArray, object? value = null, List<IObjectInfo>? objectInfoList = null)
71 32 {
33 StringConverter = stringConverter;
72 34 Name = name;
73 35 ObjectPlace = objectPlace;
74 36 Layer = layer;
Modified XFEExtension.NetCore/XFETransform/ObjectInfoImpl.cs +2 -2
@@ -2,10 +2,10 @@
2 2
3 3 internal class ObjectInfoImpl : ObjectInfo
4 4 {
5 public ObjectInfoImpl(string? name, ObjectPlace objectPlace, int layer, Type type, bool isBasicType, object? value = null) : base(name, objectPlace, layer, type, isBasicType, value)
5 public ObjectInfoImpl(IStringConverter? stringConverter, string? name, ObjectPlace objectPlace, int layer, Type? type, bool isBasicType, object? value = null) : base(stringConverter, name, objectPlace, layer, type, isBasicType, value)
6 6 {
7 7 }
8 public ObjectInfoImpl(string? name, ObjectPlace objectPlace, int layer, Type type, bool isBasicType, bool isArray, object? value, List<IObjectInfo>? objectInfoList = null) : base(name, objectPlace, layer, type, isBasicType, isArray, value, objectInfoList)
8 public ObjectInfoImpl(IStringConverter? stringConverter, string? name, ObjectPlace objectPlace, int layer, Type? type, bool isBasicType, bool isArray, object? value, List<IObjectInfo>? objectInfoList = null) : base(stringConverter, name, objectPlace, layer, type, isBasicType, isArray, value, objectInfoList)
9 9 {
10 10 }
11 11 }
Added XFEExtension.NetCore/XFETransform/StringConverter.cs +7 -0
@@ -0,0 +1,7 @@
1 namespace XFEExtension.NetCore.XFETransform;
2
3 internal abstract class StringConverter : IStringConverter
4 {
5 public abstract string OutPutObject(IObjectInfo objectInfo);
6 public abstract string OutPutSubObjects(ISubObjects subObjects);
7 }
Modified XFEExtension.NetCore/XFETransform/SubObjects.cs +1 -44
@@ -1,48 +1,5 @@
1 1 namespace XFEExtension.NetCore.XFETransform;
2 2
3 internal abstract class SubObjects(List<IObjectInfo>? objectInfoList) : SubObjectsBase(objectInfoList)
3 internal abstract class SubObjects(List<IObjectInfo>? objectInfoList, IObjectInfo parent) : SubObjectsBase(objectInfoList, parent)
4 4 {
5 public override string OutPutSubObjects()
6 {
7 var outString = string.Empty;
8 for (int i = 0; i < objectInfoList.Count; i++)
9 {
10 var obj = objectInfoList[i];
11 var tabString = string.Empty;
12 var currentConnectString = string.Empty;
13 for (int k = 0; k < obj.Layer; k++)
14 {
15 tabString += "│ ";
16 }
17 outString += tabString;
18 if (i == objectInfoList.Count - 1)
19 {
20 currentConnectString = "└─";
21 }
22 else
23 {
24 currentConnectString = "├─";
25 }
26 if (obj.IsBasicType)
27 {
28 outString += currentConnectString;
29 outString += obj.OutPut();
30 }
31 else
32 {
33 outString += $"""
34 ├─{obj.AddObjectPlace()} {XFEConverter.OutPutTypeName(obj.Type)} {obj.Name}
35 {tabString}├────┬────────────────────────────
36 {obj.OutPut()}
37 {tabString}{currentConnectString}────────────────────────────────
38
39 """;
40 }
41 }
42 if (outString.Length > 0 && outString[^1] == '\n')
43 {
44 outString = outString[..^1];
45 }
46 return outString;
47 }
48 5 }
Modified XFEExtension.NetCore/XFETransform/SubObjectsBase.cs +2 -4
@@ -2,7 +2,7 @@
2 2
3 3 namespace XFEExtension.NetCore.XFETransform;
4 4
5 internal abstract class SubObjectsBase(List<IObjectInfo>? objectInfoList) : ISubObjects
5 internal abstract class SubObjectsBase(List<IObjectInfo>? objectInfoList, IObjectInfo parent) : ISubObjects
6 6 {
7 7 protected readonly List<IObjectInfo> objectInfoList = objectInfoList ?? [];
8 8
@@ -12,7 +12,7 @@ internal abstract class SubObjectsBase(List<IObjectInfo>? objectInfoList) : ISub
12 12
13 13 public bool IsReadOnly => false;
14 14
15 protected abstract ObjectInfo Parent { get; init; }
15 public IObjectInfo Parent { get; init; } = parent;
16 16
17 17 public void Add(IObjectInfo item) => objectInfoList.Add(item);
18 18
@@ -28,8 +28,6 @@ internal abstract class SubObjectsBase(List<IObjectInfo>? objectInfoList) : ISub
28 28
29 29 public void Insert(int index, IObjectInfo item) => objectInfoList.Insert(index, item);
30 30
31 public abstract string OutPutSubObjects();
32
33 31 public bool Remove(IObjectInfo item) => objectInfoList.Remove(item);
34 32
35 33 public void RemoveAt(int index) => objectInfoList.RemoveAt(index);
Modified XFEExtension.NetCore/XFETransform/SubObjectsImpl.cs +1 -2
@@ -1,6 +1,5 @@
1 1 namespace XFEExtension.NetCore.XFETransform;
2 2
3 internal class SubObjectsImpl(ObjectInfo parent, List<IObjectInfo>? objectInfoList = null) : SubObjects(objectInfoList)
3 internal class SubObjectsImpl(IObjectInfo parent, List<IObjectInfo>? objectInfoList = null) : SubObjects(objectInfoList, parent)
4 4 {
5 protected override ObjectInfo Parent { get; init; } = parent;
6 5 }
Modified XFEExtension.NetCore/XFETransform/XFEConverter.cs +20 -12