Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

Commit 091764c

Browse files
authored
feat(custom-page): 为自定义主页添加变量辅助方法 (#115)
* feat(custom-page): 同步上游自定义主页更新 * feat(wip): 大概搭个自定义变量的框架,具体实现有待商榷 * fix: ci
1 parent fcf7b5e commit 091764c

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

App/CustomVarible.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text.Json.Nodes;
5+
using PCL.Core.IO;
6+
7+
namespace PCL.Core.App;
8+
9+
public class CustomVarible
10+
{
11+
/// <summary>
12+
/// 自定义主页变量保存路径。
13+
/// </summary>
14+
public static string VaribleJsonPath { get; } = Path.Combine(FileService.SharedDataPath, "varibles.json");
15+
16+
/// <summary>
17+
/// 存放所有自定义主页变量的 JSON 对象。
18+
/// </summary>
19+
public static JsonNode? VaribleJson;
20+
21+
public static Dictionary<string, string> VaribleDict = new();
22+
23+
public static void Set(string key, string value)
24+
{
25+
26+
}
27+
28+
public static void Get(string key, string value)
29+
{
30+
31+
}
32+
33+
public static void Init()
34+
{
35+
if (!File.Exists(VaribleJsonPath))
36+
{
37+
File.Create(VaribleJsonPath).Close();
38+
}
39+
else
40+
{
41+
try
42+
{
43+
VaribleJson = JsonNode.Parse(File.ReadAllText(VaribleJsonPath));
44+
}
45+
catch (Exception e)
46+
{
47+
Console.WriteLine(e);
48+
throw;
49+
}
50+
}
51+
}
52+
}

Utils/Exts/StringExtension.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Numerics;
88
using System.Reflection;
9+
using System.Runtime.CompilerServices;
910
using System.Text.RegularExpressions;
1011

1112
namespace PCL.Core.Utils.Exts;
@@ -142,6 +143,26 @@ public string FromB32ToB10()
142143
}
143144
}
144145

146+
extension(string input)
147+
{
148+
149+
public T ParseToEnum<T>() where T : struct, Enum
150+
{
151+
if (String.IsNullOrWhiteSpace(input))
152+
{
153+
return (T)(object)0;
154+
}
155+
else if (int.TryParse(input, out int numericValue))
156+
{
157+
return (T)(object)numericValue;
158+
}
159+
else
160+
{
161+
return Enum.Parse<T>(input, true);
162+
}
163+
}
164+
}
165+
145166
extension([NotNullWhen(false)] string? value)
146167
{
147168
/// <summary>

0 commit comments

Comments
 (0)