This repository was archived by the owner on Jan 25, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +73
-0
lines changed
Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 66using System . Linq ;
77using System . Numerics ;
88using System . Reflection ;
9+ using System . Runtime . CompilerServices ;
910using System . Text . RegularExpressions ;
1011
1112namespace 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>
You can’t perform that action at this time.
0 commit comments