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

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

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

XFEstudio/XFEExtension

添加导入和导出配置文件的方法

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

代码差异

1 个文件 +51 -0
Modified XFEExtension.NetCore/ProfileExtension/XFEProfile.cs +51 -0
@@ -148,4 +148,55 @@ public abstract class XFEProfile
148 148 /// <param name="profileInfo"></param>
149 149 /// <returns></returns>
150 150 protected static async Task AutoSaveAsync(ProfileInfo profileInfo) => await SaveProfileAsync(profileInfo);
151
152 /// <summary>
153 /// 导出指定的配置文件
154 /// </summary>
155 /// <param name="profileInfo">指定的配置文件</param>
156 /// <returns></returns>
157 public static string ExportProfile(ProfileInfo profileInfo)
158 {
159 var waitSaveProfile = Profiles.Find(x => x.Profile == profileInfo.Profile);
160 if (waitSaveProfile is null)
161 return string.Empty;
162 var saveProfileDictionary = new XFEDictionary();
163 foreach (var property in waitSaveProfile.PropertiesInfo)
164 saveProfileDictionary.Add(property.Name, SaveProfilesFunc(property));
165 return saveProfileDictionary.ToString();
166 }
167
168 /// <summary>
169 /// 导出所有配置文件
170 /// </summary>
171 /// <returns></returns>
172 public static string ExportProfiles()
173 {
174 var exportProfiles = new XFEDictionary();
175 foreach (var profile in Profiles)
176 exportProfiles.Add(profile.Profile.Name, ExportProfile(profile));
177 return exportProfiles.ToString();
178 }
179
180 /// <summary>
181 /// 导入配置文件
182 /// </summary>
183 /// <param name="profileString">配置文件字符串</param>
184 public static void ImportProfile(string profileString)
185 {
186 var importProfile = new XFEDictionary(profileString);
187 foreach (var profile in Profiles)
188 {
189 if (importProfile[profile.Profile.Name] is not null)
190 {
191 var profileContent = importProfile[profile.Profile.Name];
192 var profileContentDictionary = new XFEDictionary(profileContent!);
193 for (int i = 0; i < profile.PropertiesInfo.Count; i++)
194 {
195 var propertyInfo = profile.PropertiesInfo[i];
196 if (profileContentDictionary[propertyInfo.Name] is not null)
197 profile.PropertiesInfo[i].Property.SetValue(null, LoadProfilesFunc(profileContentDictionary[propertyInfo.Name]!, propertyInfo));
198 }
199 }
200 }
201 }
151 202 }