返回提交历史
Modified
XFEExtension.NetCore.AutoConfig.Analyzer/Generator/ProfilePropertyAutoGenerator.cs
+34
-2
Modified
XFEExtension.NetCore.AutoConfig/XFEExtension.NetCore.AutoConfig.csproj
+5
-6
Modified
XFEExtension.NetCore.AutoConfig/XFEProfile.cs
+10
-10
XFEstudio/XFEExtension.NetCore.AutoConfig
配置文件实例中的ProfilePath和ProfileExtension重命名为CurrentProfilePath和CurrentProfileExtension属性 现在,配置文件会自动生成一个ProfilePath和ProfileExtension的静态属性
6df3b36
代码差异
3 个文件
+49
-18
@@ -42,7 +42,7 @@ public class ProfilePropertyAutoGenerator : IIncrementalGenerator
42
42
var initializerBlockStatements = new List<StatementSyntax>()
43
43
{
44
44
SyntaxFactory.ParseStatement($"this.SetProfileOperation();"),
45
SyntaxFactory.ParseStatement($@"this.ProfilePath = $""{{(string.IsNullOrEmpty(this.ProfilePath) ? $""{{(global::XFEExtension.NetCore.AutoConfig.XFEProfile.ProfilesDefaultPath)}}\\{{nameof({className})}}"" : this.ProfilePath)}}{{this.ProfileFileExtension}}"";")
45
SyntaxFactory.ParseStatement($@"this.CurrentProfilePath = $""{{ProfilePath}}{{(string.IsNullOrEmpty(ProfileExtension) ? this.CurrentProfileExtension : ProfileExtension)}}"";")
46
46
};
47
47
foreach (var fieldDeclarationSyntax in fieldDeclarationSyntaxes)
48
48
{
@@ -314,7 +314,39 @@ public class ProfilePropertyAutoGenerator : IIncrementalGenerator
314
314
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
315
315
.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia($@"/// <summary>
316
316
/// 该配置文件的实例<br/><br/>
317
/// <seealso cref=""{className}.Current""/> 是 <seealso cref=""{className}""/> 配置文件类的实例数据
317
/// <seealso cref=""{className}.Current""/> 是 <seealso cref=""{className}""/> 的配置文件类的实例数据
318
/// </summary>
319
")));
320
memberDeclarationSyntaxes.Add(SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName("string"), "ProfilePath")
321
.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)))
322
.WithAccessorList(SyntaxFactory.AccessorList(SyntaxFactory.List(
323
[
324
SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
325
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
326
SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
327
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
328
])))
329
.WithInitializer(SyntaxFactory.EqualsValueClause(SyntaxFactory.ParseExpression($@"$""{{(global::XFEExtension.NetCore.AutoConfig.XFEProfile.ProfilesDefaultPath)}}\\{{nameof({className})}}""")))
330
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
331
.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia($@"/// <summary>
332
/// 该配置文件的存储位置<br/><br/>
333
/// <seealso cref=""{className}.ProfilePath""/> 是 <seealso cref=""{className}""/> 的配置文件存储路径(不包含文件扩展名,如需设置扩展名,请查阅 <seealso cref=""{className}.ProfileExtension""/> )
334
/// </summary>
335
")));
336
memberDeclarationSyntaxes.Add(SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName("string"), "ProfileExtension")
337
.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)))
338
.WithAccessorList(SyntaxFactory.AccessorList(SyntaxFactory.List(
339
[
340
SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
341
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
342
SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
343
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
344
])))
345
.WithInitializer(SyntaxFactory.EqualsValueClause(SyntaxFactory.ParseExpression("string.Empty")))
346
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
347
.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia($@"/// <summary>
348
/// 该配置文件的文件扩展名<br/><br/>
349
/// 当为空时, <seealso cref=""global::XFEExtension.NetCore.AutoConfig.XFEProfile""/> 将根据配置文件类型自动选择合适的扩展名(.xpf .json .xml等)
318
350
/// </summary>
319
351
")));
320
352
memberDeclarationSyntaxes.Add(SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName("void"), "LoadProfile")
@@ -17,19 +17,18 @@
17
17
<PackageTags>XFE;config;profile;auto</PackageTags>
18
18
<PackageReleaseNotes>## 调整
19
19
20
调整多数代码,使得其尽可能的减少使用反射的次数以提高整体代码运行性能
21
修复导入配置文件出错的bug
20
配置文件实例中的ProfilePath和ProfileExtension重命名为CurrentProfilePath和CurrentProfileExtension属性
21
现在,配置文件会自动生成一个ProfilePath和ProfileExtension的静态属性
22
22
23
23
## 新增
24
24
25
现在增加了对AOT编译的支持
26
支持在构造函数时设置默认的存储方式(XPF, Json, XML或自定义)
25
无
27
26
28
27
## 严重
29
28
30
由于AOT支持等多种原因,现在XFEProfile不再实现对配置文件的统一管理</PackageReleaseNotes>
29
无</PackageReleaseNotes>
31
30
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
32
<Version>2.0.1</Version>
31
<Version>2.0.2</Version>
33
32
<GenerateDocumentationFile>True</GenerateDocumentationFile>
34
33
</PropertyGroup>
35
34
@@ -19,11 +19,11 @@ public abstract class XFEProfile
19
19
/// <summary>
20
20
/// 配置文件存储位置
21
21
/// </summary>
22
internal protected string ProfilePath { get; set; } = string.Empty;
22
internal protected string CurrentProfilePath { get; set; } = string.Empty;
23
23
/// <summary>
24
24
/// 配置文件扩展名
25
25
/// </summary>
26
internal protected string ProfileFileExtension { get; set; } = ".xpf";
26
internal protected string CurrentProfileExtension { get; set; } = ".xpf";
27
27
/// <summary>
28
28
/// 默认配置文件存储和读取的操作模式
29
29
/// </summary>
@@ -130,7 +130,7 @@ public abstract class XFEProfile
130
130
/// <returns>配置文件实例</returns>
131
131
internal protected XFEProfile InstanceLoadProfile()
132
132
{
133
if (File.Exists(ProfilePath) && LoadOperation(this, File.ReadAllText(ProfilePath), PropertyInfoDictionary, PropertySetFuncDictionary) is XFEProfile xFEProfile)
133
if (File.Exists(CurrentProfilePath) && LoadOperation(this, File.ReadAllText(CurrentProfilePath), PropertyInfoDictionary, PropertySetFuncDictionary) is XFEProfile xFEProfile)
134
134
{
135
135
xFEProfile.Initialize();
136
136
return xFEProfile;
@@ -144,10 +144,10 @@ public abstract class XFEProfile
144
144
internal protected void InstanceSaveProfile()
145
145
{
146
146
var saveContent = SaveOperation(this, PropertyInfoDictionary, PropertyGetFuncDictionary);
147
var fileSavePath = Path.GetDirectoryName(ProfilePath);
147
var fileSavePath = Path.GetDirectoryName(CurrentProfilePath);
148
148
if (!Directory.Exists(fileSavePath) && fileSavePath is not null && fileSavePath != string.Empty)
149
149
Directory.CreateDirectory(fileSavePath);
150
File.WriteAllTextAsync(ProfilePath, saveContent);
150
File.WriteAllTextAsync(CurrentProfilePath, saveContent);
151
151
return;
152
152
}
153
153
/// <summary>
@@ -155,8 +155,8 @@ public abstract class XFEProfile
155
155
/// </summary>
156
156
internal protected void InstanceDeleteProfile()
157
157
{
158
if (File.Exists(ProfilePath))
159
File.Delete(ProfilePath);
158
if (File.Exists(CurrentProfilePath))
159
File.Delete(CurrentProfilePath);
160
160
}
161
161
/// <summary>
162
162
/// 导出配置文件
@@ -187,17 +187,17 @@ public abstract class XFEProfile
187
187
case ProfileOperationMode.XFEDictionary:
188
188
LoadOperation = XFEDictionaryLoadProfileOperation;
189
189
SaveOperation = XFEDictionarySaveProfileOperation;
190
ProfileFileExtension = ".xpf";
190
CurrentProfileExtension = ".xpf";
191
191
break;
192
192
case ProfileOperationMode.Json:
193
193
LoadOperation = JsonLoadProfileOperation;
194
194
SaveOperation = JsonSaveProfileOperation;
195
ProfileFileExtension = ".json";
195
CurrentProfileExtension = ".json";
196
196
break;
197
197
case ProfileOperationMode.Xml:
198
198
LoadOperation = XmlLoadProfileOperation;
199
199
SaveOperation = XmlSaveProfileOperation;
200
ProfileFileExtension = ".xml";
200
CurrentProfileExtension = ".xml";
201
201
break;
202
202
case ProfileOperationMode.Custom:
203
203
break;