XFEExtension
【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
关注
0
Fork
0
Star
0
返回提交历史
Modified
XFEExtension.NetCore.Analyzer.Test/XFEExtension.NetCore.Analyzer.Test.csproj
+1
-1
Modified
XFEExtension.NetCore.Test/XFEExtension.NetCore.Test.csproj
+1
-1
Renamed
XFEExtension.NetCore/ArrayExtension/AI/MatrixOfArrayExtension.cs
+0
-0
Modified
XFEExtension.NetCore/ArrayExtension/ArrayExtension.cs
+52
-48
Modified
XFEExtension.NetCore/AttributeExtension/AttributeExtension.cs
+132
-192
Modified
XFEExtension.NetCore/BufferExtension/BufferExtension.cs
+132
-139
Modified
XFEExtension.NetCore/CyberComm/CyberCommServerEventArgs.cs
+6
-6
Modified
XFEExtension.NetCore/FileExtension/FileExtension.cs
+93
-84
Modified
XFEExtension.NetCore/ObjectExtension/ObjectExtension.cs
+33
-30
Modified
XFEExtension.NetCore/ReflectionExtension/ReflectionExtension.cs
+120
-107
Modified
XFEExtension.NetCore/StringExtension/JsonStringExtension.cs
+30
-26
Modified
XFEExtension.NetCore/StringExtension/StringExtension.cs
+244
-222
Modified
XFEExtension.NetCore/ThreadExtension/ThreadExtension.cs
+63
-54
Modified
XFEExtension.NetCore/XFEChatGPT/ChatGPTInnerClass/DefaultClass/GPTMessage.cs
+1
-1
Modified
XFEExtension.NetCore/XFEExtension.NetCore.csproj
+1
-1
Modified
XFEExtension.NetCore/XFETransform/JsonConverter/JsonNodeConverter.cs
+3
-3
Modified
XFEExtension.NetCore/XFETransform/StringConverter/ColoredObjectAnalyzer.cs
+1
-1
Modified
XFEExtension.NetCore/XFETransform/StringConverter/FormattedJsonTransformer.cs
+2
-2
Modified
XFEExtension.NetCore/XFETransform/StringConverter/JsonTransformer.cs
+2
-2
XFEstudio/XFEExtension
全部更换为扩展块
ac85628
代码差异
19 个文件
+917
-920
@@ -1,7 +1,7 @@
1
1
<Project Sdk="Microsoft.NET.Sdk">
2
2
3
3
<PropertyGroup>
4
<TargetFramework>net8.0</TargetFramework>
4
<TargetFramework>net10.0</TargetFramework>
5
5
<ImplicitUsings>enable</ImplicitUsings>
6
6
<Nullable>enable</Nullable>
7
7
<OutputType>Exe</OutputType>
@@ -2,7 +2,7 @@
2
2
3
3
<PropertyGroup>
4
4
<OutputType>Exe</OutputType>
5
<TargetFramework>net8.0</TargetFramework>
5
<TargetFramework>net10.0</TargetFramework>
6
6
<ImplicitUsings>enable</ImplicitUsings>
7
7
<Nullable>enable</Nullable>
8
8
</PropertyGroup>
此文件没有可显示的逐行差异。
@@ -5,76 +5,80 @@
5
5
/// </summary>
6
6
public static class ArrayExtension
7
7
{
8
private static readonly string[] separator = ["[+-", "-+]"];
8
private static readonly string[] Separator = ["[+-", "-+]"];
9
9
10
/// <summary>
10
/// 将数组转换为XFE格式字符串
11
/// 对数组的拓展
11
12
/// </summary>
12
13
/// <typeparam name="T"></typeparam>
13
14
/// <param name="arrays"></param>
14
/// <returns></returns>
15
public static string ToXFEString<T>(this T[] arrays)
15
extension<T>(T[] arrays)
16
16
{
17
string str = string.Empty;
18
foreach (var ary in arrays)
19
{
20
if (ary is not null)
21
str += $"[+-{ary?.ToString()?.Replace("[+", "[++").Replace("+]", "++]")}-+]";
22
}
23
return str;
17
/// <summary>
18
/// 将数组转换为XFE格式字符串
19
/// </summary>
20
/// <returns></returns>
21
public string ToXFEString() => arrays.Aggregate(string.Empty, (current, ary) => current + $"[+-{ary?.ToString()?.Replace("[+", "[++").Replace("+]", "++]")}-+]");
24
22
}
23
25
24
/// <summary>
26
/// 将数组转换为XFE格式字符串
25
/// 对数组的拓展
27
26
/// </summary>
28
27
/// <typeparam name="T"></typeparam>
29
28
/// <param name="arrays"></param>
30
/// <param name="propertyName">属性名称</param>
31
/// <returns></returns>
32
public static string ToXFEString<T>(this T[] arrays, string propertyName) where T : class
29
extension<T>(T[] arrays) where T : class
33
30
{
34
string str = string.Empty;
35
foreach (var ary in arrays)
36
{
37
if (ary is not null)
38
str += $"[+-{ary?.GetType()?.GetProperty(propertyName)?.GetValue(ary)?.ToString()?.Replace("[+", "[++").Replace("+]", "++]")}-+]";
39
}
40
return str;
31
/// <summary>
32
/// 将数组转换为XFE格式字符串
33
/// </summary>
34
/// <typeparam name="T"></typeparam>
35
/// <param name="propertyName">属性名称</param>
36
/// <returns></returns>
37
public string ToXFEString(string propertyName) => arrays.Aggregate(string.Empty, (current, ary) => current + $"[+-{ary?.GetType()?.GetProperty(propertyName)?.GetValue(ary)?.ToString()?.Replace("[+", "[++").Replace("+]", "++]")}-+]");
41
38
}
42
39
43
40
44
/// <summary>
45
/// 将XFE格式字符串转换为数组
46
/// </summary>
47
/// <typeparam name="T"></typeparam>
48
41
/// <param name="str"></param>
49
/// <returns>T类型的数组</returns>
50
public static T[] ToXFEArray<T>(this string str)
42
extension(string str)
51
43
{
52
string[] strings = str.Split(separator, StringSplitOptions.RemoveEmptyEntries);
53
for (int i = 0; i < strings.Length; i++)
54
{
55
strings[i] = strings[i].Replace("[++", "[+").Replace("++]", "+]");
56
}
57
T[] array = new T[(strings.Length - 1) / 2];
58
for (int i = 0, j = 1; i < array.Length; i++, j += 2)
44
/// <summary>
45
/// 将XFE格式字符串转换为数组
46
/// </summary>
47
/// <typeparam name="T"></typeparam>
48
/// <returns>T类型的数组</returns>
49
public T[] ToXFEArray<T>()
59
50
{
60
array[i] = (T)Convert.ChangeType(strings[j], typeof(T));
51
string[] strings = str.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
52
for (int i = 0; i < strings.Length; i++)
53
{
54
strings[i] = strings[i].Replace("[++", "[+").Replace("++]", "+]");
55
}
56
var array = new T[(strings.Length - 1) / 2];
57
for (int i = 0, j = 1; i < array.Length; i++, j += 2)
58
{
59
array[i] = (T)Convert.ChangeType(strings[j], typeof(T));
60
}
61
return array;
61
62
}
62
return array;
63
63
}
64
/// <summary>
65
/// 获取数组中的类型
66
/// </summary>
64
67
65
/// <param name="objects"></param>
68
/// <returns></returns>
69
public static Type[]? GetTypes(this object[] objects)
66
extension(object[]? objects)
70
67
{
71
if (objects is null)
72
return null;
73
Type[] types = new Type[objects.Length];
74
for (int i = 0; i < objects.Length; i++)
68
/// <summary>
69
/// 获取数组中的类型
70
/// </summary>
71
/// <returns></returns>
72
public Type[]? GetTypes()
75
73
{
76
types[i] = objects[i].GetType();
74
if (objects is null)
75
return null;
76
var types = new Type[objects.Length];
77
for (int i = 0; i < objects.Length; i++)
78
{
79
types[i] = objects[i].GetType();
80
}
81
return types;
77
82
}
78
return types;
79
83
}
80
84
}
@@ -280,217 +280,157 @@ public static class AttributeExtension
280
280
}
281
281
#endregion
282
282
#region 拓展方法
283
/// <summary>
284
/// 获取该对象的给定属性的对象
285
/// </summary>
286
/// <typeparam name="T">属性类型</typeparam>
287
/// <param name="obj">对象</param>
288
public static T? GetAttribute<T>(this object obj) where T : Attribute
289
{
290
if (obj is string || obj is int || obj is double || obj is float || obj is decimal || obj is DateTime || obj is bool)
291
{
292
throw new XFEExtensionException("基础类型不支持获取属性");
293
}
294
return obj.GetType().GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
295
}
296
/// <summary>
297
/// 获取该对象的给定属性的对象列表
298
/// </summary>
299
/// <typeparam name="T">属性类型</typeparam>
283
300
284
/// <param name="obj">对象</param>
301
public static List<T?> GetAttributes<T>(this object obj) where T : Attribute
302
{
303
if (obj is string || obj is int || obj is double || obj is float || obj is decimal || obj is DateTime || obj is bool)
304
{
305
throw new XFEExtensionException("基础类型不支持获取属性");
306
}
307
return obj.GetType().GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList(); ;
308
}
309
/// <summary>
310
/// 获取给定类的某个方法的给定属性的对象
311
/// </summary>
312
/// <typeparam name="T">属性类型</typeparam>
313
/// <param name="tarClass">类</param>
314
/// <param name="methodName">类中的方法名</param>
315
/// <returns></returns>
316
public static T? GetAttributeInMethod<T>(this object tarClass, string methodName) where T : Attribute
285
extension(object obj)
317
286
{
318
var className = tarClass.GetType().ToString();
319
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
320
var method = type.GetMethod(methodName);
321
if (method is null)
287
/// <summary>
288
/// 获取该对象的给定属性的对象
289
/// </summary>
290
/// <typeparam name="T">属性类型</typeparam>
291
public T? GetAttribute<T>() where T : Attribute
322
292
{
323
throw new XFEExtensionException($"未找到方法{methodName}");
293
if (obj is string or int or double or float or decimal or DateTime or bool)
294
{
295
throw new XFEExtensionException("基础类型不支持获取属性");
296
}
297
return obj.GetType().GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
324
298
}
325
else
326
{
299
300
/// <summary>
301
/// 获取该对象的给定属性的对象列表
302
/// </summary>
303
/// <typeparam name="T">属性类型</typeparam>
304
public List<T?> GetAttributes<T>() where T : Attribute => obj is string or int or double or float or decimal or DateTime or bool ? throw new XFEExtensionException("基础类型不支持获取属性") : obj.GetType().GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
305
306
/// <summary>
307
/// 获取给定类的某个方法的给定属性的对象
308
/// </summary>
309
/// <typeparam name="T">属性类型</typeparam>
310
/// <param name="methodName">类中的方法名</param>
311
/// <returns></returns>
312
public T? GetAttributeInMethod<T>(string methodName) where T : Attribute
313
{
314
var className = obj.GetType().ToString();
315
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
316
var method = type.GetMethod(methodName);
317
if (method is null)
318
{
319
throw new XFEExtensionException($"未找到方法{methodName}");
320
}
327
321
return method.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
328
322
}
329
323
330
}
331
/// <summary>
332
/// 获取给定类的某个方法的给定属性的对象列表
333
/// </summary>
334
/// <typeparam name="T">属性类型</typeparam>
335
/// <param name="tarClass">类</param>
336
/// <param name="methodName">类中的方法名</param>
337
/// <returns></returns>
338
public static List<T?> GetAttributesInMethod<T>(this object tarClass, string methodName) where T : Attribute
339
{
340
var className = tarClass.GetType().ToString();
341
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
342
var method = type.GetMethod(methodName);
343
if (method is null)
344
{
345
throw new XFEExtensionException($"未找到方法{methodName}");
346
}
347
else
348
{
349
return method.GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
350
}
351
}
352
/// <summary>
353
/// 获取给定类的某个字段的给定属性的对象
354
/// </summary>
355
/// <typeparam name="T">属性类型</typeparam>
356
/// <param name="tarClass">类</param>
357
/// <param name="fieldName">类中的字段名称</param>
358
/// <returns></returns>
359
public static T? GetAttributeInField<T>(this object tarClass, string fieldName) where T : Attribute
360
{
361
var className = tarClass.GetType().ToString();
362
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
363
var field = type.GetField(fieldName);
364
if (field is null)
365
{
366
throw new XFEExtensionException($"未找到字段{fieldName}");
324
/// <summary>
325
/// 获取给定类的某个方法的给定属性的对象列表
326
/// </summary>
327
/// <typeparam name="T">属性类型</typeparam>
328
/// <param name="methodName">类中的方法名</param>
329
/// <returns></returns>
330
public List<T?> GetAttributesInMethod<T>(string methodName) where T : Attribute
331
{
332
var className = obj.GetType().ToString();
333
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
334
var method = type.GetMethod(methodName);
335
return method is null ? throw new XFEExtensionException($"未找到方法{methodName}") : method.GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
367
336
}
368
else
369
{
337
338
/// <summary>
339
/// 获取给定类的某个字段的给定属性的对象
340
/// </summary>
341
/// <typeparam name="T">属性类型</typeparam>
342
/// <param name="fieldName">类中的字段名称</param>
343
/// <returns></returns>
344
public T? GetAttributeInField<T>(string fieldName) where T : Attribute
345
{
346
var className = obj.GetType().ToString();
347
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
348
var field = type.GetField(fieldName);
349
if (field is null)
350
throw new XFEExtensionException($"未找到字段{fieldName}");
370
351
return field.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
371
352
}
372
}
373
/// <summary>
374
/// 获取给定类的某个字段的给定属性的对象列表
375
/// </summary>
376
/// <typeparam name="T">属性类型</typeparam>
377
/// <param name="tarClass">类</param>
378
/// <param name="fieldName">类中的字段名称</param>
379
/// <returns></returns>
380
public static List<T?> GetAttributesInField<T>(this object tarClass, string fieldName) where T : Attribute
381
{
382
var className = tarClass.GetType().ToString();
383
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
384
var field = type.GetField(fieldName);
385
if (field is null)
386
{
387
throw new XFEExtensionException($"未找到字段{fieldName}");
388
}
389
else
390
{
391
return field.GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
392
}
393
}
394
/// <summary>
395
/// 获取给定类的某个属性的给定属性的对象
396
/// </summary>
397
/// <typeparam name="T">属性类型</typeparam>
398
/// <param name="tarClass">类</param>
399
/// <param name="propertyName">类中的属性名称</param>
400
/// <returns></returns>
401
public static T? GetAttributeInProperty<T>(this object tarClass, string propertyName) where T : Attribute
402
{
403
var className = tarClass.GetType().ToString();
404
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
405
var property = type.GetProperty(propertyName);
406
if (property is null)
407
{
408
throw new XFEExtensionException($"未找到属性{propertyName}");
409
}
410
else
411
{
412
return property.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
413
}
414
}
415
/// <summary>
416
/// 获取给定类的某个属性的给定属性的对象列表
417
/// </summary>
418
/// <typeparam name="T">属性类型</typeparam>
419
/// <param name="tarClass">类</param>
420
/// <param name="propertyName">类中的属性名称</param>
421
/// <returns></returns>
422
public static List<T?> GetAttributesInProperty<T>(this object tarClass, string propertyName) where T : Attribute
423
{
424
var className = tarClass.GetType().ToString();
425
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
426
var property = type.GetProperty(propertyName);
427
if (property is null)
428
{
429
throw new XFEExtensionException($"未找到属性{propertyName}");
353
354
/// <summary>
355
/// 获取给定类的某个字段的给定属性的对象列表
356
/// </summary>
357
/// <typeparam name="T">属性类型</typeparam>
358
/// <param name="fieldName">类中的字段名称</param>
359
/// <returns></returns>
360
public List<T?> GetAttributesInField<T>(string fieldName) where T : Attribute
361
{
362
var className = obj.GetType().ToString();
363
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
364
var field = type.GetField(fieldName);
365
return field is null ? throw new XFEExtensionException($"未找到字段{fieldName}") : field.GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
430
366
}
431
else
432
{
433
return property.GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
367
368
/// <summary>
369
/// 获取给定类的某个属性的给定属性的对象
370
/// </summary>
371
/// <typeparam name="T">属性类型</typeparam>
372
/// <param name="propertyName">类中的属性名称</param>
373
/// <returns></returns>
374
public T? GetAttributeInProperty<T>(string propertyName) where T : Attribute
375
{
376
var className = obj.GetType().ToString();
377
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
378
var property = type.GetProperty(propertyName);
379
return property is null ? throw new XFEExtensionException($"未找到属性{propertyName}") : property.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
434
380
}
435
}
436
/// <summary>
437
/// 获取给定类的给定方法的给定参数的给定属性的对象
438
/// </summary>
439
/// <typeparam name="T">属性类型</typeparam>
440
/// <param name="tarClass">类</param>
441
/// <param name="methodName">方法名</param>
442
/// <param name="paramName">参数名</param>
443
/// <returns></returns>
444
public static T? GetAttributeInParam<T>(this object tarClass, string methodName, string paramName) where T : Attribute
445
{
446
var className = tarClass.GetType().ToString();
447
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
448
var method = type.GetMethod(methodName);
449
if (method is null)
450
{
451
throw new XFEExtensionException($"未找到方法{methodName}");
381
382
/// <summary>
383
/// 获取给定类的某个属性的给定属性的对象列表
384
/// </summary>
385
/// <typeparam name="T">属性类型</typeparam>
386
/// <param name="propertyName">类中的属性名称</param>
387
/// <returns></returns>
388
public List<T?> GetAttributesInProperty<T>(string propertyName) where T : Attribute
389
{
390
var className = obj.GetType().ToString();
391
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
392
var property = type.GetProperty(propertyName);
393
return property is null ? throw new XFEExtensionException($"未找到属性{propertyName}") : property.GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
452
394
}
453
else
454
{
395
396
/// <summary>
397
/// 获取给定类的给定方法的给定参数的给定属性的对象
398
/// </summary>
399
/// <typeparam name="T">属性类型</typeparam>
400
/// <param name="methodName">方法名</param>
401
/// <param name="paramName">参数名</param>
402
/// <returns></returns>
403
public T? GetAttributeInParam<T>(string methodName, string paramName) where T : Attribute
404
{
405
var className = obj.GetType().ToString();
406
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
407
var method = type.GetMethod(methodName);
408
if (method is null)
409
throw new XFEExtensionException($"未找到方法{methodName}");
455
410
var param = method.GetParameters().FirstOrDefault(x => x.Name == paramName);
456
411
if (param is null)
457
{
458
412
throw new XFEExtensionException($"未找到参数{paramName}");
459
}
460
else
461
{
462
return param.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
463
}
413
return param.GetCustomAttributes(typeof(T), false).FirstOrDefault() as T;
464
414
}
465
}
466
/// <summary>
467
/// 获取给定类的给定方法的给定参数的给定属性的对象列表
468
/// </summary>
469
/// <typeparam name="T">属性类型</typeparam>
470
/// <param name="tarClass">类名(区分大小写)</param>
471
/// <param name="methodName">方法名</param>
472
/// <param name="paramName">参数名</param>
473
/// <returns></returns>
474
public static List<T?> GetAttributesInParam<T>(this object tarClass, string methodName, string paramName) where T : Attribute
475
{
476
var className = tarClass.GetType().ToString();
477
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
478
var method = type.GetMethod(methodName);
479
if (method is null)
480
{
481
throw new XFEExtensionException($"未找到方法{methodName}");
482
}
483
else
484
{
485
var param = method.GetParameters().FirstOrDefault(x => x.Name == paramName);
486
if (param is null)
487
{
488
throw new XFEExtensionException($"未找到参数{paramName}");
489
}
490
else
415
416
/// <summary>
417
/// 获取给定类的给定方法的给定参数的给定属性的对象列表
418
/// </summary>
419
/// <typeparam name="T">属性类型</typeparam>
420
/// <param name="methodName">方法名</param>
421
/// <param name="paramName">参数名</param>
422
/// <returns></returns>
423
public List<T?> GetAttributesInParam<T>(string methodName, string paramName) where T : Attribute
424
{
425
var className = obj.GetType().ToString();
426
var type = Assembly.GetCallingAssembly().GetType(className, false, true) ?? throw new XFEExtensionException($"未找到类{className}");
427
var method = type.GetMethod(methodName);
428
if (method is null)
491
429
{
492
return param.GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
430
throw new XFEExtensionException($"未找到方法{methodName}");
493
431
}
432
var param = method.GetParameters().FirstOrDefault(x => x.Name == paramName);
433
return param is null ? throw new XFEExtensionException($"未找到参数{paramName}") : param.GetCustomAttributes(typeof(T), false).Select(x => x as T).ToList();
494
434
}
495
435
}
496
436
#endregion
@@ -7,55 +7,82 @@ namespace XFEExtension.NetCore.BufferExtension;
7
7
/// </summary>
8
8
public static class BufferExtension
9
9
{
10
/// <summary>
11
/// 获取第一个匹配Buffer的位置
12
/// </summary>
13
10
/// <param name="buffer"></param>
14
/// <param name="targetBuffer">要匹配Buffer</param>
15
/// <returns>没有查找到为-1</returns>
16
public static int IndexOf(this byte[] buffer, byte[] targetBuffer)
11
extension(byte[] buffer)
17
12
{
18
int index = -1;
19
for (int i = 0; i < buffer.Length; i++)
13
/// <summary>
14
/// 获取第一个匹配Buffer的位置
15
/// </summary>
16
/// <param name="targetBuffer">要匹配Buffer</param>
17
/// <returns>没有查找到为-1</returns>
18
public int IndexOf(byte[] targetBuffer)
20
19
{
21
if (buffer[i] == targetBuffer[0])
20
int index = -1;
21
for (int i = 0; i < buffer.Length; i++)
22
22
{
23
if (buffer[i] != targetBuffer[0])
24
continue;
23
25
bool isMatch = true;
24
for (int j = 0; j < targetBuffer.Length; j++)
26
for (int j = targetBuffer.Length - 1; j >= 0; j--)
25
27
{
26
if (buffer[i + j] != targetBuffer[j])
27
{
28
isMatch = false;
29
break;
30
}
31
}
32
if (isMatch)
33
{
34
index = i;
28
if (buffer[i + j] == targetBuffer[j])
29
continue;
30
isMatch = false;
35
31
break;
36
32
}
33
if (!isMatch)
34
continue;
35
index = i;
36
break;
37
37
}
38
return index;
38
39
}
39
return index;
40
}
41
/// <summary>
42
/// 获取所有匹配的Buffer的位置
43
/// </summary>
44
/// <param name="buffer"></param>
45
/// <param name="targetBuffer">要匹配的Buffer</param>
46
/// <param name="shareable">是否可以共用</param>
47
/// <returns>查找到的位置数组</returns>
48
public static int[] IndexesOf(this byte[] buffer, byte[] targetBuffer, bool shareable = false)
49
{
50
var indexes = new List<int>();
51
for (int i = 0; i < buffer.Length; i++)
40
41
/// <summary>
42
/// 获取所有匹配的Buffer的位置
43
/// </summary>
44
/// <param name="targetBuffer">要匹配的Buffer</param>
45
/// <param name="shareable">是否可以共用</param>
46
/// <returns>查找到的位置数组</returns>
47
public int[] IndexesOf(byte[] targetBuffer, bool shareable = false)
48
{
49
var indexes = new List<int>();
50
for (int i = 0; i < buffer.Length; i++)
51
{
52
if (buffer[i] != targetBuffer[0])
53
continue;
54
bool isMatch = !targetBuffer.Where((t, j) => buffer[i + j] != t).Any();
55
if (!isMatch) continue;
56
indexes.Add(i);
57
if (!shareable)
58
i += targetBuffer.Length - 1;
59
}
60
return [.. indexes];
61
}
62
63
/// <summary>
64
/// 替换Buffer中的指定Buffer为目标Buffer
65
/// </summary>
66
/// <param name="originBuffer"></param>
67
/// <param name="targetBuffer"></param>
68
/// <returns>替换后的Buffer</returns>
69
public byte[] Replace(byte[] originBuffer, byte[] targetBuffer)
52
70
{
53
if (buffer[i] == targetBuffer[0])
71
if (originBuffer is null || originBuffer.LongLength == 0)
72
{
73
throw new ArgumentException("Origin buffer cannot be null or empty.");
74
}
75
if (buffer is null || buffer.LongLength == 0)
76
{
77
return [];
78
}
79
List<byte> result = [];
80
for (long i = 0; i <= buffer.LongLength - originBuffer.LongLength; i++)
54
81
{
55
82
bool isMatch = true;
56
for (int j = 0; j < targetBuffer.Length; j++)
83
for (long j = 0; j < originBuffer.LongLength; j++)
57
84
{
58
if (buffer[i + j] != targetBuffer[j])
85
if (buffer[i + j] != originBuffer[j])
59
86
{
60
87
isMatch = false;
61
88
break;
@@ -63,90 +90,52 @@ public static class BufferExtension
63
90
}
64
91
if (isMatch)
65
92
{
66
indexes.Add(i);
67
if (!shareable)
68
i += targetBuffer.Length - 1;
93
result.AddRange(targetBuffer);
94
i += originBuffer.LongLength - 1;
69
95
}
70
}
71
}
72
return [.. indexes];
73
}
74
/// <summary>
75
/// 替换Buffer中的指定Buffer为目标Buffer
76
/// </summary>
77
/// <param name="buffer"></param>
78
/// <param name="originBuffer"></param>
79
/// <param name="targetBuffer"></param>
80
/// <returns>替换后的Buffer</returns>
81
public static byte[] Replace(this byte[] buffer, byte[] originBuffer, byte[] targetBuffer)
82
{
83
if (originBuffer is null || originBuffer.LongLength == 0)
84
{
85
throw new ArgumentException("Origin buffer cannot be null or empty.");
86
}
87
if (buffer is null || buffer.LongLength == 0)
88
{
89
return [];
90
}
91
List<byte> result = [];
92
for (long i = 0; i <= buffer.LongLength - originBuffer.LongLength; i++)
93
{
94
bool isMatch = true;
95
for (long j = 0; j < originBuffer.LongLength; j++)
96
{
97
if (buffer[i + j] != originBuffer[j])
96
else
98
97
{
99
isMatch = false;
100
break;
98
result.Add(buffer[i]);
101
99
}
102
100
}
103
if (isMatch)
101
for (long i = buffer.LongLength - originBuffer.LongLength + 1; i < buffer.LongLength; i++)
104
102
{
105
result.AddRange(targetBuffer);
106
i += originBuffer.LongLength - 1;
103
if (i >= 0)
104
result.Add(buffer[i]);
107
105
}
108
else
109
{
110
result.Add(buffer[i]);
111
}
112
}
113
for (long i = buffer.LongLength - originBuffer.LongLength + 1; i < buffer.LongLength; i++)
114
{
115
if (i >= 0)
116
result.Add(buffer[i]);
106
return [.. result];
117
107
}
118
return [.. result];
119
}
120
108
121
/// <summary>
122
/// 分割Buffer
123
/// </summary>
124
/// <param name="buffer"></param>
125
/// <param name="targetBuffer">分割器</param>
126
/// <returns></returns>
127
public static List<byte[]> Split(this byte[] buffer, byte[] targetBuffer)
128
{
129
var indexes = buffer.IndexesOf(targetBuffer);
130
var buffers = new List<byte[]>();
131
long index = 0;
132
for (long i = 0; i < indexes.LongLength; i++)
109
/// <summary>
110
/// 分割Buffer
111
/// </summary>
112
/// <param name="targetBuffer">分割器</param>
113
/// <returns></returns>
114
public List<byte[]> Split(byte[] targetBuffer)
133
115
{
134
var newBuffer = new byte[indexes[i] - index];
135
for (long j = index; j < indexes[i]; j++)
116
var indexes = buffer.IndexesOf(targetBuffer);
117
var buffers = new List<byte[]>();
118
long index = 0;
119
for (long i = 0; i < indexes.LongLength; i++)
120
{
121
var newBuffer = new byte[indexes[i] - index];
122
for (long j = index; j < indexes[i]; j++)
123
{
124
newBuffer[j - index] = buffer[j];
125
}
126
buffers.Add(newBuffer);
127
index = indexes[i] + targetBuffer.LongLength;
128
}
129
var lastBuffer = new byte[buffer.LongLength - index];
130
for (long i = index; i < buffer.LongLength; i++)
136
131
{
137
newBuffer[j - index] = buffer[j];
132
lastBuffer[i - index] = buffer[i];
138
133
}
139
buffers.Add(newBuffer);
140
index = indexes[i] + targetBuffer.LongLength;
141
}
142
var lastBuffer = new byte[buffer.LongLength - index];
143
for (long i = index; i < buffer.LongLength; i++)
144
{
145
lastBuffer[i - index] = buffer[i];
134
buffers.Add(lastBuffer);
135
return buffers;
146
136
}
147
buffers.Add(lastBuffer);
148
return buffers;
149
137
}
138
150
139
/// <summary>
151
140
/// 将Buffer转换为XFEBuffer
152
141
/// </summary>
@@ -163,44 +152,48 @@ public static class BufferExtension
163
152
}
164
153
return [.. packedBuffer];
165
154
}
166
/// <summary>
167
/// 为Buffer添加头部并封装为XFEBuffer
168
/// </summary>
155
169
156
/// <param name="buffer"></param>
170
/// <param name="headers"></param>
171
/// <returns></returns>
172
public static byte[] AddHeaderAndPack(this byte[] buffer, params string[] headers)
157
extension(byte[] buffer)
173
158
{
174
var buffers = new List<byte[]>();
175
foreach (var header in headers)
159
/// <summary>
160
/// 为Buffer添加头部并封装为XFEBuffer
161
/// </summary>
162
/// <param name="headers"></param>
163
/// <returns></returns>
164
public byte[] AddHeaderAndPack(params string[] headers)
176
165
{
177
buffers.Add(Encoding.UTF8.GetBytes(header));
166
var buffers = new List<byte[]>();
167
foreach (var header in headers)
168
{
169
buffers.Add(Encoding.UTF8.GetBytes(header));
170
}
171
buffers.Add(buffer);
172
return buffers.PackBuffer();
178
173
}
179
buffers.Add(buffer);
180
return buffers.PackBuffer();
181
}
182
/// <summary>
183
/// 为Buffer添加头部并封装为XFEBuffer
184
/// </summary>
185
/// <param name="buffer"></param>
186
/// <param name="headers"></param>
187
/// <returns></returns>
188
public static byte[] AddHeaderAndPack(this byte[] buffer, params byte[] headers)
189
{
190
return new List<byte[]>() { headers, buffer }.PackBuffer();
191
}
192
/// <summary>
193
/// 将XEFBuffer转换为BufferList
194
/// </summary>
195
/// <param name="buffer"></param>
196
/// <returns></returns>
197
public static List<byte[]> UnPackBuffer(this byte[] buffer)
198
{
199
var unPackedBuffers = new List<byte[]>();
200
foreach (var unPackedBuffer in buffer.Split([0x01, 0x02, 0x03]))
174
175
/// <summary>
176
/// 为Buffer添加头部并封装为XFEBuffer
177
/// </summary>
178
/// <param name="headers"></param>
179
/// <returns></returns>
180
public byte[] AddHeaderAndPack(params byte[] headers)
201
181
{
202
unPackedBuffers.Add(unPackedBuffer.Replace([0x02, 0x02, 0x03], [0x02, 0x03]));
182
return new List<byte[]>() { headers, buffer }.PackBuffer();
183
}
184
185
/// <summary>
186
/// 将XEFBuffer转换为BufferList
187
/// </summary>
188
/// <returns></returns>
189
public List<byte[]> UnPackBuffer()
190
{
191
var unPackedBuffers = new List<byte[]>();
192
foreach (var unPackedBuffer in buffer.Split([0x01, 0x02, 0x03]))
193
{
194
unPackedBuffers.Add(unPackedBuffer.Replace([0x02, 0x02, 0x03], [0x02, 0x03]));
195
}
196
return unPackedBuffers;
203
197
}
204
return unPackedBuffers;
205
198
}
206
199
}
@@ -7,16 +7,16 @@ namespace XFEExtension.NetCore.CyberComm;
7
7
/// <summary>
8
8
/// CyberComm服务器事件参数
9
9
/// </summary>
10
/// <param name="RequestURL">请求时的URL地址</param>
10
/// <param name="RequestUrl">请求时的URL地址</param>
11
11
/// <param name="MessageType"> 消息类型 </param>
12
12
/// <param name="CurrentWebSocket"> 当前WebSocket </param>
13
/// <param name="WSHeader"> 客户端请求头 </param>
13
/// <param name="WsHeader"> 客户端请求头 </param>
14
14
/// <param name="Exception"> 异常消息(如果有的话) </param>
15
15
/// <param name="IpAddress"> 客户端IP地址 </param>
16
16
/// <param name="TextMessage"> 文本消息 </param>
17
17
/// <param name="BinaryMessage"> 二进制消息 </param>
18
18
/// <param name="EndOfMessage">消息是否结束</param>
19
public abstract record CyberCommServerEventArgs(Uri? RequestURL, BackMessageType MessageType, WebSocket CurrentWebSocket, NameValueCollection WSHeader, XFECyberCommException? Exception, string IpAddress, string? TextMessage, byte[]? BinaryMessage, bool EndOfMessage)
19
public abstract record CyberCommServerEventArgs(Uri? RequestUrl, BackMessageType MessageType, WebSocket CurrentWebSocket, NameValueCollection WsHeader, XFECyberCommException? Exception, string IpAddress, string? TextMessage, byte[]? BinaryMessage, bool EndOfMessage)
20
20
{
21
21
/// <summary>
22
22
/// 发送文本消息
@@ -83,13 +83,13 @@ public abstract record CyberCommServerEventArgs(Uri? RequestURL, BackMessageType
83
83
throw new XFECyberCommException("强制关闭服务器端连接时出现异常", ex);
84
84
}
85
85
}
86
internal CyberCommServerEventArgs(Uri? requestURL, WebSocket webSocket, string message, string ipAddress, NameValueCollection wsHeader, bool endOfMessage) : this(requestURL, BackMessageType.Text, webSocket, wsHeader, null, ipAddress, message, null, endOfMessage)
86
internal CyberCommServerEventArgs(Uri? requestUrl, WebSocket webSocket, string message, string ipAddress, NameValueCollection wsHeader, bool endOfMessage) : this(requestUrl, BackMessageType.Text, webSocket, wsHeader, null, ipAddress, message, null, endOfMessage)
87
87
{
88
88
}
89
internal CyberCommServerEventArgs(Uri? requestURL, WebSocket webSocket, byte[] bytes, string ipAddress, NameValueCollection wsHeader, bool endOfMessage) : this(requestURL, BackMessageType.Binary, webSocket, wsHeader, null, ipAddress, null, bytes, endOfMessage)
89
internal CyberCommServerEventArgs(Uri? requestUrl, WebSocket webSocket, byte[] bytes, string ipAddress, NameValueCollection wsHeader, bool endOfMessage) : this(requestUrl, BackMessageType.Binary, webSocket, wsHeader, null, ipAddress, null, bytes, endOfMessage)
90
90
{
91
91
}
92
internal CyberCommServerEventArgs(Uri? requestURL, WebSocket webSocket, XFECyberCommException ex, string ipAddress, NameValueCollection wsHeader) : this(requestURL, BackMessageType.Error, webSocket, wsHeader, ex, ipAddress, null, null, true)
92
internal CyberCommServerEventArgs(Uri? requestUrl, WebSocket webSocket, XFECyberCommException ex, string ipAddress, NameValueCollection wsHeader) : this(requestUrl, BackMessageType.Error, webSocket, wsHeader, ex, ipAddress, null, null, true)
93
93
{
94
94
}
95
95
}
@@ -37,70 +37,75 @@ public static class FileExtension
37
37
fileStream.Flush();
38
38
fileStream.Close();
39
39
}
40
/// <summary>
41
/// 读取文件中的字符串
42
/// </summary>
40
43
41
/// <param name="name"></param>
44
/// <param name="content">读取的内容</param>
45
/// <returns>被读取的文件是否存在</returns>
46
public static bool ReadOut(this string name, out string? content)
47
{
48
FileInfo fileInfo = new(name);
49
if (fileInfo.Exists)
50
{
51
using StreamReader streamReader = fileInfo.OpenText();
52
content = streamReader.ReadToEnd();
53
streamReader.Close();
54
return true;
55
}
56
else
57
{
58
content = string.Empty;
59
return false;
60
}
61
}
62
/// <summary>
63
/// 读取文件中的字符串
64
/// </summary>
65
/// <param name="fileName">目标文件路径及文件名</param>
66
/// <returns>目标文件内容,如不存在则返回-1</returns>
67
public static string? ReadOut(this string fileName)
42
extension(string name)
68
43
{
69
FileInfo fileInfo = new(fileName);
70
if (fileInfo.Exists)
71
{
72
using var streamReader = fileInfo.OpenText();
73
var text = streamReader.ReadToEnd();
74
streamReader.Close();
75
return text;
76
}
77
else
44
/// <summary>
45
/// 读取文件中的字符串
46
/// </summary>
47
/// <param name="content">读取的内容</param>
48
/// <returns>被读取的文件是否存在</returns>
49
public bool ReadOut(out string? content)
78
50
{
79
return "-1";
51
FileInfo fileInfo = new(name);
52
if (fileInfo.Exists)
53
{
54
using StreamReader streamReader = fileInfo.OpenText();
55
content = streamReader.ReadToEnd();
56
streamReader.Close();
57
return true;
58
}
59
else
60
{
61
content = string.Empty;
62
return false;
63
}
80
64
}
81
}
82
/// <summary>
83
/// 读取文件中的字符串
84
/// </summary>
85
/// <param name="fileName"></param>
86
/// <returns></returns>
87
[Obsolete("序列化方法在.NET 8.0中已经不再受支持")]
88
public static T? ReadOutObj<T>(this string fileName)
89
{
90
FileInfo fileInfo = new(fileName);
91
if (fileInfo.Exists)
65
66
/// <summary>
67
/// 读取文件中的字符串
68
/// </summary>
69
/// <returns>目标文件内容,如不存在则返回-1</returns>
70
public string? ReadOut()
92
71
{
93
using var fileStream = fileInfo.OpenRead();
94
BinaryFormatter bf = new();
95
var result = (T)bf.Deserialize(fileStream);
96
fileStream.Close();
97
return result;
72
FileInfo fileInfo = new(name);
73
if (fileInfo.Exists)
74
{
75
using var streamReader = fileInfo.OpenText();
76
var text = streamReader.ReadToEnd();
77
streamReader.Close();
78
return text;
79
}
80
else
81
{
82
return "-1";
83
}
98
84
}
99
else
85
86
/// <summary>
87
/// 读取文件中的字符串
88
/// </summary>
89
/// <returns></returns>
90
[Obsolete("序列化方法在.NET 8.0中已经不再受支持")]
91
public T? ReadOutObj<T>()
100
92
{
101
return default;
93
FileInfo fileInfo = new(name);
94
if (fileInfo.Exists)
95
{
96
using var fileStream = fileInfo.OpenRead();
97
BinaryFormatter bf = new();
98
var result = (T)bf.Deserialize(fileStream);
99
fileStream.Close();
100
return result;
101
}
102
else
103
{
104
return default;
105
}
102
106
}
103
107
}
108
104
109
/// <summary>
105
110
/// 读取文件中的字符串
106
111
/// </summary>
@@ -227,38 +232,42 @@ public static class FileExtension
227
232
catch { }
228
233
return null; // 如果没有找到占用文件的进程,返回null
229
234
}
230
/// <summary>
231
/// 获取文件的有效起始位置
232
/// </summary>
235
233
236
/// <param name="fileStream">文件流</param>
234
/// <param name="startPosition">起始搜寻位置</param>
235
/// <param name="endPosition">结束搜寻位置</param>
236
/// <returns>一个长整型,介于起始位置和结束位置之间</returns>
237
public static async Task<long> GetValidPosition(this FileStream fileStream, long startPosition, long endPosition)
237
extension(FileStream fileStream)
238
238
{
239
long seekPosition = endPosition;
240
fileStream.Seek(startPosition, SeekOrigin.Begin);
241
byte[] buffer = new byte[endPosition - startPosition];
242
await fileStream.ReadExactlyAsync(buffer.AsMemory(0, (int)(endPosition - startPosition)));
243
for (int i = buffer.Length - 1; i >= 0; i--)
239
/// <summary>
240
/// 获取文件的有效起始位置
241
/// </summary>
242
/// <param name="startPosition">起始搜寻位置</param>
243
/// <param name="endPosition">结束搜寻位置</param>
244
/// <returns>一个长整型,介于起始位置和结束位置之间</returns>
245
public async Task<long> GetValidPosition(long startPosition, long endPosition)
244
246
{
245
if (buffer[i] != 0)
246
break;
247
seekPosition--;
247
long seekPosition = endPosition;
248
fileStream.Seek(startPosition, SeekOrigin.Begin);
249
byte[] buffer = new byte[endPosition - startPosition];
250
await fileStream.ReadExactlyAsync(buffer.AsMemory(0, (int)(endPosition - startPosition)));
251
for (int i = buffer.Length - 1; i >= 0; i--)
252
{
253
if (buffer[i] != 0)
254
break;
255
seekPosition--;
256
}
257
return seekPosition > startPosition ? seekPosition : startPosition;
248
258
}
249
return seekPosition > startPosition ? seekPosition : startPosition;
259
260
/// <summary>
261
/// 获取文件的有效起始位置
262
/// </summary>
263
/// <param name="startPosition">起始搜寻位置</param>
264
/// <returns>一个长整型,介于起始位置和结束位置之间</returns>
265
public async Task<long> GetValidPosition(long startPosition) => await GetValidPosition(fileStream, startPosition, fileStream.Length);
266
267
/// <summary>
268
/// 获取文件的有效起始位置
269
/// </summary>
270
/// <returns>一个长整型,介于起始位置和结束位置之间</returns>
271
public async Task<long> GetValidPosition() => await GetValidPosition(fileStream, 0, fileStream.Length);
250
272
}
251
/// <summary>
252
/// 获取文件的有效起始位置
253
/// </summary>
254
/// <param name="fileStream">文件流</param>
255
/// <param name="startPosition">起始搜寻位置</param>
256
/// <returns>一个长整型,介于起始位置和结束位置之间</returns>
257
public static async Task<long> GetValidPosition(this FileStream fileStream, long startPosition) => await GetValidPosition(fileStream, startPosition, fileStream.Length);
258
/// <summary>
259
/// 获取文件的有效起始位置
260
/// </summary>
261
/// <param name="fileStream">文件流</param>
262
/// <returns>一个长整型,介于起始位置和结束位置之间</returns>
263
public static async Task<long> GetValidPosition(this FileStream fileStream) => await GetValidPosition(fileStream, 0, fileStream.Length);
264
273
}
@@ -5,44 +5,47 @@
5
5
/// </summary>
6
6
public static class ObjectExtension
7
7
{
8
/// <summary>
9
/// 进行浅拷贝
10
/// </summary>
11
/// <typeparam name="T"></typeparam>
12
8
/// <param name="source"></param>
13
/// <returns>浅拷贝后的对象</returns>
14
/// <exception cref="ArgumentNullException">无类型错误</exception>
15
public static T ActiveCopyOf<T>(this T source) where T : class
16
{
17
return source is null
18
? throw new ArgumentNullException(nameof(source))
19
: (T)source.GetType().GetMethod("MemberwiseClone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?.Invoke(source, null)!;
20
}
21
/// <summary>
22
/// 进行静态拷贝
23
/// </summary>
24
9
/// <typeparam name="T"></typeparam>
25
/// <param name="source"></param>
26
/// <returns>静态拷贝后的对象</returns>
27
public static T? StaticCopyOf<T>(this T source) where T : class
10
extension<T>(T source) where T : class
28
11
{
29
if (source is null)
30
{
31
return default;
32
}
33
var fields = typeof(T).GetFields();
34
var properties = typeof(T).GetProperties();
35
var newObject = Activator.CreateInstance<T>();
36
foreach (var property in properties)
12
/// <summary>
13
/// 进行浅拷贝
14
/// </summary>
15
/// <returns>浅拷贝后的对象</returns>
16
/// <exception cref="ArgumentNullException">无类型错误</exception>
17
public T ActiveCopyOf()
37
18
{
38
property.SetValue(newObject, property.GetValue(source));
19
return source is null
20
? throw new ArgumentNullException(nameof(source))
21
: (T)source.GetType().GetMethod("MemberwiseClone", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)?.Invoke(source, null)!;
39
22
}
40
foreach (var field in fields)
23
24
/// <summary>
25
/// 进行静态拷贝
26
/// </summary>
27
/// <returns>静态拷贝后的对象</returns>
28
public T? StaticCopyOf()
41
29
{
42
field.SetValue(newObject, field.GetValue(source));
30
if (source is null)
31
{
32
return default;
33
}
34
var fields = typeof(T).GetFields();
35
var properties = typeof(T).GetProperties();
36
var newObject = Activator.CreateInstance<T>();
37
foreach (var property in properties)
38
{
39
property.SetValue(newObject, property.GetValue(source));
40
}
41
foreach (var field in fields)
42
{
43
field.SetValue(newObject, field.GetValue(source));
44
}
45
return newObject;
43
46
}
44
return newObject;
45
47
}
48
46
49
/// <summary>
47
50
/// 比较两个对象的属性是否完全相同而非对象本身相同
48
51
/// </summary>
@@ -29,7 +29,7 @@ public class GPTMessage(string role, string content)
29
29
private static string SetRoleAndCheckRoleLegal(string inputRole)
30
30
{
31
31
string lowerRole = inputRole.ToLower();
32
if (lowerRole == "system" || lowerRole == "user" || lowerRole == "assistant")
32
if (lowerRole is "system" or "user" or "assistant")
33
33
{
34
34
return lowerRole;
35
35
}
@@ -1,7 +1,7 @@
1
1
<Project Sdk="Microsoft.NET.Sdk">
2
2
3
3
<PropertyGroup>
4
<TargetFramework>net8.0</TargetFramework>
4
<TargetFramework>net10.0</TargetFramework>
5
5
<ImplicitUsings>enable</ImplicitUsings>
6
6
<Nullable>enable</Nullable>
7
7
<GenerateDocumentationFile>True</GenerateDocumentationFile>
@@ -69,7 +69,7 @@ public class JsonNodeConverter(string jsonString)
69
69
{
70
70
currentSymbol = JsonSymbol.InvertedBrace;
71
71
currentState = CurrentState.None;
72
if (lastSymbol == JsonSymbol.Text || lastSymbol == JsonSymbol.DoubleQuotationMark)
72
if (lastSymbol is JsonSymbol.Text or JsonSymbol.DoubleQuotationMark)
73
73
{
74
74
currentValueType = JudgeValueType(ref currentPropertyValue);
75
75
currentJsonComplexJsonNode = GetJsonNodeByIndex(jsonNode, currentPosition);
@@ -124,7 +124,7 @@ public class JsonNodeConverter(string jsonString)
124
124
if ((currentState != CurrentState.Property && currentState != CurrentState.StringPropertyValue) || currentState == CurrentState.AfterPropertyValue || currentState == CurrentState.AfterProperty)
125
125
{
126
126
currentState = CurrentState.None;
127
if (lastSymbol == JsonSymbol.Text || lastSymbol == JsonSymbol.DoubleQuotationMark)
127
if (lastSymbol is JsonSymbol.Text or JsonSymbol.DoubleQuotationMark)
128
128
{
129
129
currentValueType = JudgeValueType(ref currentPropertyValue);
130
130
currentJsonComplexJsonNode = GetJsonNodeByIndex(jsonNode, currentPosition);
@@ -165,7 +165,7 @@ public class JsonNodeConverter(string jsonString)
165
165
currentPosition[currentLayer + 1] += 1;
166
166
if (currentState != CurrentState.ListValue)
167
167
currentState = CurrentState.BeforeProperty;
168
if (lastSymbol == JsonSymbol.Text || lastSymbol == JsonSymbol.DoubleQuotationMark)
168
if (lastSymbol is JsonSymbol.Text or JsonSymbol.DoubleQuotationMark)
169
169
{
170
170
currentValueType = JudgeValueType(ref currentPropertyValue);
171
171
currentJsonComplexJsonNode = GetJsonNodeByIndex(jsonNode, currentPosition);