Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions App/CustomVarible.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json.Nodes;
using PCL.Core.IO;

namespace PCL.Core.App;

public class CustomVarible
{
/// <summary>
/// 自定义主页变量保存路径。
/// </summary>
public static string VaribleJsonPath { get; } = Path.Combine(FileService.SharedDataPath, "varibles.json");

/// <summary>
/// 存放所有自定义主页变量的 JSON 对象。
/// </summary>
public static JsonNode? VaribleJson;

public static Dictionary<string, string> VaribleDict = new();

public static void Set(string key, string value)
{

}

public static void Get(string key, string value)
{

}

public static void Init()
{
if (!File.Exists(VaribleJsonPath))
{
File.Create(VaribleJsonPath).Close();
}
else
{
try
{
VaribleJson = JsonNode.Parse(File.ReadAllText(VaribleJsonPath));
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
}
17 changes: 16 additions & 1 deletion Utils/Exts/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

namespace PCL.Core.Utils.Exts;
Expand Down Expand Up @@ -200,8 +201,22 @@ public static List<string> RegexSearch(this string str, Regex regex)
/// </summary>
// ReSharper disable once InconsistentNaming
public static bool IsASCII(this string str)
=> str.All(c => c < 128);

public static T ParseToEnum<T>(this string str) where T : struct, Enum
{
return str.All(c => c < 128);
if (String.IsNullOrWhiteSpace(str))
{
return (T)(object)0;
}
else if (int.TryParse(str, out int numericValue))
{
return (T)(object)numericValue;
}
else
{
return Enum.Parse<T>(str, true);
}
}

public static bool StartsWithF(this string str, string prefix, bool ignoreCase = false)
Expand Down