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

XFEExtension.NetCore.AutoConfig

【DLL】自动实现配置文件的存储

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

XFEstudio/XFEExtension.NetCore.AutoConfig

add-为每个配置文件类增加静态ProfilePath属性,可以使用引用路径,优先级大于ProfilePath特性

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

代码差异

8 个文件 +49 -34
Renamed AutoConfig.Analyzer.Test/AutoConfig.Analyzer.Test.csproj +0 -0
此文件没有可显示的逐行差异。
Added AutoConfig.Analyzer.Test/Program.cs +12 -0
@@ -0,0 +1,12 @@
1 namespace AutoConfig.Analyzer.Test;
2
3 public class Program
4 {
5 [SMTest]
6 public static void MainTest()
7 {
8 SystemProfile.TestNum = 3;
9 Console.WriteLine(SystemProfile.TestNum);
10 Console.WriteLine(SystemProfile.ProfilePath);
11 }
12 }
Added AutoConfig.Analyzer.Test/SystemProfile.cs +10 -0
@@ -0,0 +1,10 @@
1 using XFEExtension.NetCore.AutoConfig;
2
3 namespace AutoConfig.Analyzer.Test;
4
5 public partial class SystemProfile
6 {
7 [ProfileProperty]
8 private int testNum;
9 public SystemProfile() => ProfilePath = @"C:\Users\XFEstudio\Downloads\SystemProfile.xfe";
10 }
Deleted AutoConfig.Test/Program.cs +0 -11
@@ -1,11 +0,0 @@
1 namespace AutoConfig.Test;
2
3 internal class Program
4 {
5 [SMTest]
6 public static void MainTest()
7 {
8 SystemProfile.MyNum = 2;
9 Console.WriteLine(SystemProfile.MyNum);
10 }
11 }
Deleted AutoConfig.Test/SystemProfile.cs +0 -10
@@ -1,10 +0,0 @@
1 using XFEExtension.NetCore.AutoConfig;
2
3 namespace AutoConfig.Test;
4
5 [ProfilePath(@$"C:\Users\XFEstudio\Downloads\{nameof(SystemProfile)}.xfe")]
6 public partial class SystemProfile
7 {
8 [ProfileProperty]
9 private int myNum;
10 }
Modified XFEExtension.NetCore.AutoConfig.Analyzer/Generator/ProfilePropertyAutoGenerator.cs +20 -2
@@ -136,7 +136,7 @@ namespace XFEExtension.NetCore.AutoConfig.Generator
136 136 /// ○ <seealso langword=""{fieldName}""/> = <seealso langword=""value""/>;<br/>";
137 137 #endregion
138 138 }
139 setExpressionStatements.Add(SyntaxFactory.ExpressionStatement(SyntaxFactory.ParseExpression($"global::XFEExtension.NetCore.AutoConfig.XFEProfile.SaveProfile(typeof({className}))")));
139 setExpressionStatements.Add(SyntaxFactory.ExpressionStatement(SyntaxFactory.ParseExpression($"global::XFEExtension.NetCore.AutoConfig.XFEProfile.SaveProfile(new(typeof({className}), ProfilePath))")));
140 140 #region Set方法中的保存方法的注释
141 141 triviaText += $@"
142 142 /// ○ <seealso cref=""global::XFEExtension.NetCore.AutoConfig.XFEProfile.SaveProfile(ProfileInfo)""/>";
@@ -218,6 +218,24 @@ namespace XFEExtension.NetCore.AutoConfig.Generator
218 218 triviaText += string.Join("<br/>\n", propertyDeclarationSyntaxes.Select(propertyDeclarationSyntax => $"/// ○ <seealso cref=\"{propertyDeclarationSyntax.Identifier}\"/>")) + "\n/// </code><br/>\n/// <code>来自<seealso cref=\"global::XFEExtension.NetCore.AutoConfig.XFEProfile\"/></code>\n/// </remarks>\n";
219 219 var memberDeclarations = new List<MemberDeclarationSyntax>
220 220 {
221 SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName("string"), "ProfilePath")
222 .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)))
223 .WithAccessorList(SyntaxFactory.AccessorList(SyntaxFactory.List(
224 new[]
225 {
226 SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
227 .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
228 SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
229 .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
230 })))
231 .WithInitializer(SyntaxFactory.EqualsValueClause(SyntaxFactory.ParseExpression(@"""""")))
232 .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
233 .WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia($@"/// <summary>
234 /// 该配置文件的自动存储和读取路径<br/>
235 /// 设置的时候记得带上文件名和后缀<br/>
236 /// <seealso cref=""ProfilePath""/> 是 <seealso cref=""{className}""/> 配置文件类的自动存储读取路径
237 /// </summary>
238 ")),
221 239 SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName(className), "Current")
222 240 .WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword)))
223 241 .AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.Attribute(SyntaxFactory.ParseName("global::XFEExtension.NetCore.AutoConfig.ProfileInstanceAttribute")))))
@@ -242,7 +260,7 @@ namespace XFEExtension.NetCore.AutoConfig.Generator
242 260 var staticConstructorSyntax = SyntaxFactory.ConstructorDeclaration(className)
243 261 .AddModifiers(SyntaxFactory.Token(SyntaxKind.StaticKeyword))
244 262 .WithBody(SyntaxFactory.Block(
245 SyntaxFactory.ParseStatement($"global::XFEExtension.NetCore.AutoConfig.XFEProfile.LoadProfiles(typeof({className}));")));
263 SyntaxFactory.ParseStatement($"global::XFEExtension.NetCore.AutoConfig.XFEProfile.LoadProfiles([new(typeof({className}), ProfilePath)]);")));
246 264 if (classDeclaration.AttributeLists.Any(IsAutoLoadProfileAttribute))
247 265 {
248 266 var autoLoadProfileAttribute = classDeclaration.AttributeLists.First(attributeList => IsAutoLoadProfileAttribute(attributeList)).Attributes.First();
Modified XFEExtension.NetCore.AutoConfig.sln +5 -9
@@ -9,11 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XFEExtension.NetCore.AutoCo
9 9 EndProject
10 10 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XFEExtension.NetCore.AutoConfig.Analyzer", "XFEExtension.NetCore.AutoConfig.Analyzer\XFEExtension.NetCore.AutoConfig.Analyzer.csproj", "{223198F6-C372-46F7-83E0-DC2504E7FDD3}"
11 11 EndProject
12 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoConfig.Test", "AutoConfig.Test\AutoConfig.Test.csproj", "{3F06E105-A7D9-42E4-8555-50760120B372}"
13 ProjectSection(ProjectDependencies) = postProject
14 {223198F6-C372-46F7-83E0-DC2504E7FDD3} = {223198F6-C372-46F7-83E0-DC2504E7FDD3}
15 {33769964-C49C-4997-BB87-F8DB9669C98E} = {33769964-C49C-4997-BB87-F8DB9669C98E}
16 EndProjectSection
12 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoConfig.Analyzer.Test", "AutoConfig.Analyzer.Test\AutoConfig.Analyzer.Test.csproj", "{30010077-451E-4DEA-9596-72208E41B2A2}"
17 13 EndProject
18 14 Global
19 15 GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -29,10 +25,10 @@ Global
29 25 {223198F6-C372-46F7-83E0-DC2504E7FDD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 26 {223198F6-C372-46F7-83E0-DC2504E7FDD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 27 {223198F6-C372-46F7-83E0-DC2504E7FDD3}.Release|Any CPU.Build.0 = Release|Any CPU
32 {3F06E105-A7D9-42E4-8555-50760120B372}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 {3F06E105-A7D9-42E4-8555-50760120B372}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 {3F06E105-A7D9-42E4-8555-50760120B372}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 {3F06E105-A7D9-42E4-8555-50760120B372}.Release|Any CPU.Build.0 = Release|Any CPU
28 {30010077-451E-4DEA-9596-72208E41B2A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 {30010077-451E-4DEA-9596-72208E41B2A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 {30010077-451E-4DEA-9596-72208E41B2A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 {30010077-451E-4DEA-9596-72208E41B2A2}.Release|Any CPU.Build.0 = Release|Any CPU
36 32 EndGlobalSection
37 33 GlobalSection(SolutionProperties) = preSolution
38 34 HideSolutionNode = FALSE
Modified XFEExtension.NetCore.AutoConfig/XFEExtension.NetCore.AutoConfig.csproj +2 -2
@@ -21,13 +21,13 @@
21 21
22 22 ## 新增
23 23
24 增加ProfilePath特性,可以为每一个配置文件类单独统一设置存储路径
24 为每个配置文件类增加静态ProfilePath属性,可以使用引用路径,优先级大于ProfilePath特性
25 25
26 26 ## 严重
27 27
28 28 无</PackageReleaseNotes>
29 29 <PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
30 <Version>1.1.0</Version>
30 <Version>1.1.1</Version>
31 31 </PropertyGroup>
32 32
33 33 <ItemGroup>