obfuz/Editor/Utils/ConfigUtil.cs

79 lines
1.9 KiB
C#
Raw Permalink Normal View History

2025-07-01 18:46:09 +08:00
using Obfuz.Settings;
using System;
namespace Obfuz.Utils
{
public static class ConfigUtil
{
public static bool ParseBool(string str)
{
switch (str.ToLowerInvariant())
{
case "1":
case "true": return true;
case "0":
case "false": return false;
default: throw new Exception($"Invalid bool value {str}");
}
}
public static bool? ParseNullableBool(string str)
{
if (string.IsNullOrEmpty(str))
{
return null;
}
switch (str.ToLowerInvariant())
{
case "1":
case "true": return true;
case "0":
case "false": return false;
default: throw new Exception($"Invalid bool value {str}");
}
}
public static int? ParseNullableInt(string str)
{
if (string.IsNullOrEmpty(str))
{
return null;
}
return int.Parse(str);
}
public static long? ParseNullableLong(string str)
{
if (string.IsNullOrEmpty(str))
{
return null;
}
return long.Parse(str);
}
public static float? ParseNullableFloat(string str)
{
if (string.IsNullOrEmpty(str))
{
return null;
}
return float.Parse(str);
}
public static double? ParseNullableDouble(string str)
{
if (string.IsNullOrEmpty(str))
{
return null;
}
return double.Parse(str);
}
2025-07-01 18:46:09 +08:00
public static ObfuscationLevel ParseObfuscationLevel(string str)
{
return (ObfuscationLevel)Enum.Parse(typeof(ObfuscationLevel), str);
}
}
}