XFEExtension
【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等
关注
0
Fork
0
Star
0
返回提交历史
Modified
README.md
+49
-16
Modified
XFEExtension.NetCore.Analyzer.Test/AppPath.cs
+1
-1
Modified
XFEExtension.NetCore.Analyzer.Test/SystemProfile.cs
+18
-0
Modified
XFEExtension.NetCore.Analyzer/Generator/PathPropertyAutoGenerator.cs
+10
-8
Modified
XFEExtension.NetCore/CyberComm/CyberCommServer.cs
+11
-3
Modified
XFEExtension.NetCore/XFEExtension.NetCore.csproj
+5
-3
XFEstudio/XFEExtension
fix-修复了路径自动实现的部分bug change-调整了CyberCommServer的构造函数,使得其更加合理 change-更新md文档API说明
5e51a7f
代码差异
6 个文件
+94
-31
@@ -24,13 +24,13 @@ XFEExtension库适用于各种C#项目,特别适合在需要提高代码可读
24
24
25
25
```csharp
26
26
//创建配置文件类
27
static partial class SystemProfile
27
partial class SystemProfile
28
28
{
29
29
[ProfileProperty]
30
static string name;
30
string name;
31
31
32
32
[ProfileProperty]
33
static int _age;
33
int _age;
34
34
}
35
35
36
36
//使用配置文件
@@ -49,51 +49,84 @@ class Program
49
49
#### 设置get和set方法
50
50
51
51
```csharp
52
static partial class SystemProfile
52
partial class SystemProfile
53
53
{
54
54
[ProfileProperty]
55
55
[ProfilePropertyAddGet(@"Console.WriteLine(""获取了Name"")")]
56
[ProfilePropertyAddGet("return name")]
56
[ProfilePropertyAddGet("return Current.name")]
57
57
[ProfilePropertyAddSet(@"Console.WriteLine(""设置了Name"")")]
58
[ProfilePropertyAddSet("name = value")]
59
private static string name = string.Empty;
58
[ProfilePropertyAddSet("Current.name = value")]
59
string name = string.Empty;
60
60
61
61
[ProfileProperty]
62
62
[ProfilePropertyAddGet(@"Console.WriteLine(""获取了Age"")")]
63
[ProfilePropertyAddGet("return _age")]
63
[ProfilePropertyAddGet("return Current._age")]
64
64
[ProfilePropertyAddSet(@"Console.WriteLine(""设置了Age"")")]
65
[ProfilePropertyAddSet("_age = value")]
66
private static int _age;
65
[ProfilePropertyAddSet("Current._age = value")]
66
int _age;
67
67
}
68
68
```
69
69
70
70
#### 设置初始值
71
71
72
72
```csharp
73
static partial class SystemProfile
73
partial class SystemProfile
74
74
{
75
75
[ProfileProperty]
76
private static string name = "John Wick";
76
string name = "John Wick";
77
77
78
78
[ProfileProperty]
79
private static int _age = 59;
79
int _age = 59;
80
80
}
81
81
```
82
82
83
83
#### 为属性添加注释
84
84
85
85
```csharp
86
static partial class SystemProfile
86
partial class SystemProfile
87
87
{
88
88
/// <summary>
89
89
/// 名称
90
90
/// 这段注释会自动添加至自动生成的Name属性上
91
91
/// </summary>
92
92
[ProfileProperty]
93
private static string name;
93
string name;
94
94
95
95
[ProfileProperty]
96
private static int _age;
96
int _age;
97
}
98
```
99
100
#### 使用部分方法来设置get和set方法
101
102
```csharp
103
partial class SystemProfile
104
{
105
[ProfileProperty]
106
string name;
107
108
[ProfileProperty]
109
int _age;
110
111
static partial void GetNameProperty()
112
{
113
Console.WriteLine("获取了Name");
114
}
115
116
static partial void SetNameProperty(string value)
117
{
118
Console.WriteLine($"设置了Name:从{Name}变为了{value}");
119
}
120
121
static partial void GetAgeProperty()
122
{
123
Console.WriteLine("获取了Age");
124
}
125
126
static partial void SetAgeProperty(int value)
127
{
128
Console.WriteLine($"设置了Age:从{Age}变为了{value}");
129
}
97
130
}
98
131
```
99
132
@@ -5,5 +5,5 @@ namespace XFEExtension.NetCore.Analyzer.Test;
5
5
public partial class AppPath
6
6
{
7
7
[AutoPath]
8
readonly string myTestPath = "MyTestPath/Test";
8
readonly static string myTestPath = "MyTestPath/Test";
9
9
}
@@ -8,4 +8,22 @@ public partial class SystemProfile
8
8
int _age = 1;
9
9
[ProfileProperty]
10
10
string name = "12";
11
static partial void GetNameProperty()
12
{
13
Console.WriteLine("获取了Name");
14
}
15
static partial void SetNameProperty(string value)
16
{
17
Console.WriteLine($"设置了Name:从{Name}变为了{value}");
18
}
19
20
static partial void GetAgeProperty()
21
{
22
Console.WriteLine("获取了Age");
23
}
24
25
static partial void SetAgeProperty(int value)
26
{
27
Console.WriteLine($"设置了Age:从{Age}变为了{value}");
28
}
11
29
}
@@ -30,6 +30,7 @@ namespace XFEExtension.NetCore.Analyzer.Generator
30
30
}
31
31
var className = classDeclaration.Identifier.ValueText;
32
32
var properties = new List<PropertyDeclarationSyntax>();
33
var enableCheckProperties = new List<PropertyDeclarationSyntax>();
33
34
foreach (var fieldDeclarationSyntax in fieldDeclarationSyntaxes)
34
35
{
35
36
var variableDeclaration = fieldDeclarationSyntax.Declaration.Variables.First();
@@ -65,8 +66,8 @@ namespace XFEExtension.NetCore.Analyzer.Generator
65
66
{
66
67
SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
67
68
.WithBody(SyntaxFactory.Block(
68
SyntaxFactory.ExpressionStatement(SyntaxFactory.ParseExpression($"global::XFEExtension.NetCore.PathExtension.XFEAutoPath.CheckPathExistAndCreate(Options.{fieldName}, Options.{enableCheckPropertyName})")),
69
SyntaxFactory.ReturnStatement(SyntaxFactory.ParseExpression($"Options.{fieldName}"))))
69
SyntaxFactory.ExpressionStatement(SyntaxFactory.ParseExpression($"global::XFEExtension.NetCore.PathExtension.XFEAutoPath.CheckPathExistAndCreate({fieldName}, Options.{enableCheckPropertyName})")),
70
SyntaxFactory.ReturnStatement(SyntaxFactory.ParseExpression($"{fieldName}"))))
70
71
})))
71
72
.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia(triviaText));
72
73
var enableCheckProperty = SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName("bool"), enableCheckPropertyName)
@@ -81,9 +82,9 @@ namespace XFEExtension.NetCore.Analyzer.Generator
81
82
.WithInitializer(SyntaxFactory.EqualsValueClause(SyntaxFactory.ParseExpression("true")))
82
83
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));
83
84
properties.Add(property.NormalizeWhitespace());
84
properties.Add(enableCheckProperty.NormalizeWhitespace());
85
enableCheckProperties.Add(enableCheckProperty.NormalizeWhitespace());
85
86
}
86
var profileClassSyntaxTree = GeneratePathClassSyntaxTree(classDeclaration, properties, fileScopedNamespaceDeclarationSyntax);
87
var profileClassSyntaxTree = GeneratePathClassSyntaxTree(classDeclaration, properties, enableCheckProperties, fileScopedNamespaceDeclarationSyntax);
87
88
context.AddSource($"{className}.g.cs", profileClassSyntaxTree.ToString());
88
89
}
89
90
}
@@ -103,20 +104,20 @@ namespace XFEExtension.NetCore.Analyzer.Generator
103
104
104
105
public static IEnumerable<FieldDeclarationSyntax> GetFieldDeclarations(ClassDeclarationSyntax classDeclaration) => classDeclaration.DescendantNodes()
105
106
.OfType<FieldDeclarationSyntax>()
106
.Where(fieldDeclarationSyntax => fieldDeclarationSyntax.AttributeLists.Any(IsAutoPathAttribute) && !fieldDeclarationSyntax.Modifiers.Any(SyntaxKind.StaticKeyword));
107
.Where(fieldDeclarationSyntax => fieldDeclarationSyntax.AttributeLists.Any(IsAutoPathAttribute) && fieldDeclarationSyntax.Modifiers.Any(SyntaxKind.StaticKeyword));
107
108
108
109
public static IEnumerable<ClassDeclarationSyntax> GetClassDeclarations(SyntaxNode rootNode) => rootNode.DescendantNodes()
109
110
.OfType<ClassDeclarationSyntax>()
110
111
.Where(classDeclaration => classDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword));
111
112
112
private static SyntaxTree GeneratePathClassSyntaxTree(ClassDeclarationSyntax classDeclaration, IEnumerable<PropertyDeclarationSyntax> propertyDeclarationSyntaxes, FileScopedNamespaceDeclarationSyntax fileScopedNamespaceDeclarationSyntax)
113
private static SyntaxTree GeneratePathClassSyntaxTree(ClassDeclarationSyntax classDeclaration, List<PropertyDeclarationSyntax> propertyDeclarationSyntaxes, List<PropertyDeclarationSyntax> enableCheckDeclarationSyntaxes, FileScopedNamespaceDeclarationSyntax fileScopedNamespaceDeclarationSyntax)
113
114
{
114
115
var className = classDeclaration.Identifier.ValueText;
115
116
var triviaText = $@"/// <remarks>
116
117
/// <code><seealso cref=""{className}""/> 已生成以下路径:</code><br/>
117
118
/// <code>
118
119
";
119
triviaText += string.Join("<br/>\n", propertyDeclarationSyntaxes.Select(propertyDeclarationSyntax => $"/// ○ <seealso cref=\"{propertyDeclarationSyntax.Identifier}\"/>")) + "\n/// </code><br/>\n/// <code>来自<seealso cref=\"global::XFEExtension.NetCore.ProfileExtension.XFEProfile\"/></code>\n/// </remarks>\n";
120
triviaText += string.Join("<br/>\n", propertyDeclarationSyntaxes.Select(propertyDeclarationSyntax => $"/// ○ <seealso cref=\"{propertyDeclarationSyntax.Identifier}\"/>")) + "\n/// </code><br/>\n/// <code>来自<seealso cref=\"global::XFEExtension.NetCore.PathExtension\"/></code>\n/// </remarks>\n";
120
121
var memberDeclarations = new List<MemberDeclarationSyntax>()
121
122
{
122
123
SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName(className), "Options")
@@ -134,11 +135,12 @@ namespace XFEExtension.NetCore.Analyzer.Generator
134
135
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
135
136
.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia($@"/// <summary>
136
137
/// 配置选项<br/>
137
/// <seealso cref=""Current""/> 是 <seealso cref=""{className}""/> 类的配置选项
138
/// <seealso cref=""Options""/> 是 <seealso cref=""{className}""/> 类的配置选项
138
139
/// </summary>
139
140
"))
140
141
};
141
142
memberDeclarations.AddRange(propertyDeclarationSyntaxes);
143
memberDeclarations.AddRange(enableCheckDeclarationSyntaxes);
142
144
var pathClass = SyntaxFactory.ClassDeclaration(className)
143
145
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PartialKeyword))
144
146
.AddMembers(memberDeclarations.ToArray())
@@ -146,9 +146,8 @@ public class CyberCommServer
146
146
/// <summary>
147
147
/// CyberComm服务器,使用端口创建
148
148
/// </summary>
149
/// <param name="autoReceiveCompletedMessage">是否自动接收完整消息</param>
150
149
/// <param name="listenPorts">监听端口</param>
151
public CyberCommServer(bool autoReceiveCompletedMessage = true, params int[] listenPorts)
150
public CyberCommServer(params int[] listenPorts)
152
151
{
153
152
var serverURLs = new List<string>();
154
153
foreach (var port in listenPorts)
@@ -156,7 +155,16 @@ public class CyberCommServer
156
155
serverURLs.Add($"http://*:{port}/");
157
156
}
158
157
this.serverURLs = [.. serverURLs];
159
AutoReceiveCompletedMessage = autoReceiveCompletedMessage;
158
AutoReceiveCompletedMessage = true;
159
}
160
/// <summary>
161
/// CyberComm服务器,使用URL创建
162
/// </summary>
163
/// <param name="serverURLs">服务器URL</param>
164
public CyberCommServer(params string[] serverURLs)
165
{
166
this.serverURLs = serverURLs;
167
AutoReceiveCompletedMessage = true;
160
168
}
161
169
/// <summary>
162
170
/// CyberComm服务器,使用URL创建
@@ -19,11 +19,13 @@
19
19
<PackageTags>XFE;拓展;GPT;Server;服务器;测试;XFEExtension</PackageTags>
20
20
<PackageReleaseNotes>## 调整
21
21
22
配置文件自动实现:现在配置文件有实例了,外部静态访问内部实例数据,添加了属性Get、Set通知的部分声明方法
22
修复了路径自动实现的部分bug
23
调整了CyberCommServer的构造函数,使得其更加合理
24
更新了md文档API说明
23
25
24
26
## 新增
25
27
26
新增文件路径管理自动实现:现在,不必为了担心文件夹路径不存在而烦恼了,现在管理器会自动创建文件夹
28
无
27
29
28
30
## 严重
29
31
@@ -32,7 +34,7 @@
32
34
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
33
35
<PackageLicenseFile>LICENSE</PackageLicenseFile>
34
36
<AssemblyOriginatorKeyFile>..\XFEstudio.pfx</AssemblyOriginatorKeyFile>
35
<Version>2.10.0</Version>
37
<Version>2.10.1</Version>
36
38
<Authors>XFEstudio</Authors>
37
39
</PropertyGroup>
38
40