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

XFEExtension.NetCore.AutoConfig

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

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

XFEstudio/XFEExtension.NetCore.AutoConfig

修改readme文件和程序集版本

c490728
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

2 个文件 +66 -15
Modified README.md +61 -11
@@ -10,7 +10,7 @@ XFEExtension.NetCore.AutoConfig是一个可以自动实现配置文件存储的
10 10
11 11 ```csharp
12 12 //创建配置文件类
13 partial class SystemProfile
13 partial class SystemProfile : XFEProfile
14 14 {
15 15 [ProfileProperty]
16 16 string name;
@@ -32,17 +32,66 @@ class Program
32 32 }
33 33 ```
34 34
35 #### 修改存储格式
36
37 ```csharp
38 //配置文件类
39 partial class SystemProfile : XFEProfile
40 {
41 [ProfileProperty]
42 string name;
43
44 [ProfileProperty]
45 int _age;
46
47 public SystemProfile()
48 {
49 DefaultProfileOperationMode = ProfileOperationMode.Xml; // 改用XML格式存储配置文件,文件扩展名会自动更改为.xml
50 }
51 }
52 ```
53
54 #### 自定义存储路径、文件扩展名和存储方法
55
56 ```csharp
57 //配置文件类
58 partial class SystemProfile : XFEProfile
59 {
60 [ProfileProperty]
61 string name;
62
63 [ProfileProperty]
64 int _age;
65
66 public SystemProfile()
67 {
68 DefaultProfileOperationMode = ProfileOperationMode.Custom; // 设置为自定义存储方法
69 ProfilePath = $"MyPath/MySubPath/{nameof(SystemProfile)}"; // 设置路径为MyPath/MySubPath/SystemProfile
70 ProfileExtension = ".ini"; // 设置文件扩展名为.ini文件
71 LoadOperation = (profileInstance, profileString, propertyInfoDictionary, propertySetFuncDictionary) => return XXX; // 自定义配置文件的加载方法,使用Lambda表达式
72 SaveOperation = MyCustomSaveProfileOperation; // 自定义配置文件的保存方法,使用已有的方法
73 }
74
75 // 自定义的配置文件保存方法
76 public static string MyCustomSaveProfileOperation(XFEProfile profileInstance, Dictionary<string, Type> propertyInfoDictionary, Dictionary<string, GetValueDelegate> propertyGetFuncDictionary) => return XXX;
77 }
78 ```
79
35 80 #### 使用ProfileList和ProfileDictionary来储存集合或字典
36 81
37 82 ```csharp
38 83 //配置文件类
39 partial class SystemProfile
84 partial class SystemProfile : XFEProfile
40 85 {
41 86 [ProfileProperty]
42 ProfileList<SystemProfile, string> nameList = [];
87 [ProfilePropertyAddGet("Current.nameList.CurrentProfile = Current")]
88 [ProfilePropertyAddGet("return Current.nameList")]
89 ProfileList<string> nameList = [];
43 90
44 91 [ProfileProperty]
45 ProfileDictionary<SystemProfile, string, long> nameIdDictionary = [];
92 [ProfilePropertyAddGet("Current.nameIdDictionary.CurrentProfile = Current")]
93 [ProfilePropertyAddGet("return Current.nameIdDictionary")]
94 ProfileDictionary<string, long> nameIdDictionary = [];
46 95 }
47 96
48 97 //使用配置文件
@@ -61,7 +110,7 @@ class Program
61 110 #### 设置get和set方法
62 111
63 112 ```csharp
64 partial class SystemProfile
113 partial class SystemProfile : XFEProfile
65 114 {
66 115 [ProfileProperty]
67 116 [ProfilePropertyAddGet(@"Console.WriteLine(""获取了Name"")")]
@@ -82,7 +131,7 @@ partial class SystemProfile
82 131 #### 设置初始值
83 132
84 133 ```csharp
85 partial class SystemProfile
134 partial class SystemProfile : XFEProfile
86 135 {
87 136 [ProfileProperty]
88 137 string name = "John Wick";
@@ -95,7 +144,7 @@ partial class SystemProfile
95 144 #### 为属性添加注释
96 145
97 146 ```csharp
98 partial class SystemProfile
147 partial class SystemProfile : XFEProfile
99 148 {
100 149 /// <summary>
101 150 /// 名称
@@ -112,7 +161,7 @@ partial class SystemProfile
112 161 #### 使用部分方法来设置get和set方法
113 162
114 163 ```csharp
115 partial class SystemProfile
164 partial class SystemProfile : XFEProfile
116 165 {
117 166 [ProfileProperty]
118 167 string name;
@@ -125,7 +174,7 @@ partial class SystemProfile
125 174 Console.WriteLine("获取了Name");
126 175 }
127 176
128 static partial void SetNameProperty(string value)
177 static partial void SetNameProperty(ref string value)
129 178 {
130 179 Console.WriteLine($"设置了Name:从{Name}变为了{value}");
131 180 }
@@ -135,9 +184,10 @@ partial class SystemProfile
135 184 Console.WriteLine("获取了Age");
136 185 }
137 186
138 static partial void SetAgeProperty(int value)
187 static partial void SetAgeProperty(ref int value)
139 188 {
140 Console.WriteLine($"设置了Age:从{Age}变为了{value}");
189 value = 1999; // 可以直接设置值
190 Console.WriteLine($"设置了Age:从{Age}变为了1999");
141 191 }
142 192 }
143 193 ```
Modified XFEExtension.NetCore.AutoConfig/XFEExtension.NetCore.AutoConfig.csproj +5 -4
@@ -17,17 +17,18 @@
17 17 <PackageTags>XFE;config;profile;auto</PackageTags>
18 18 <PackageReleaseNotes>## 调整
19 19
20 调整了ProfileList的泛型顺序和名称
20 调整多数代码,使得其尽可能的减少使用反射的次数以提高整体代码运行性能
21 21
22 22 ## 新增
23 23
24 新增ProfileDictionary,与ProfileList类似,可以在增删改的时候自动存储
24 现在增加了对AOT编译的支持
25 支持在构造函数时设置默认的存储方式(XPF, Json, XML或自定义)
25 26
26 27 ## 严重
27 28
28 无</PackageReleaseNotes>
29 由于AOT支持等多种原因,现在XFEProfile不再实现对配置文件的统一管理</PackageReleaseNotes>
29 30 <PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
30 <Version>1.3.0</Version>
31 <Version>2.0.0</Version>
31 32 <GenerateDocumentationFile>True</GenerateDocumentationFile>
32 33 </PropertyGroup>
33 34