仿真平台内核初版 -tlib库 包含<sparc arm riscv powerPC>

This commit is contained in:
liuwb
2026-02-07 20:43:43 +08:00
parent de61f9e2b0
commit b3117648be
9748 changed files with 4309137 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
using System;
using System.Linq;
namespace Antmicro.OptionsParser
{
public static class ParseHelper
{
public static bool TryParse<T>(string str, out T value)
{
object result;
if(TryParse(str, typeof(T), out result))
{
value = (T)result;
return true;
}
value = default(T);
return false;
}
public static bool TryParse(string str, Type type, out object value)
{
if(str == null)
{
value = null;
return false;
}
if(type == typeof(string))
{
value = str;
return true;
}
if(type.IsEnum)
{
try
{
value = Enum.Parse(type, str, true);
return true;
}
catch(ArgumentException)
{
value = null;
return false;
}
}
if(!SupportedTypes.Contains(type))
{
value = null;
return false;
}
var parameters = new object[] { str, null };
var parseMethod = type.GetMethod("TryParse", new [] { typeof(string), type.MakeByRefType() });
var result = (bool)parseMethod.Invoke(null, parameters);
value = parameters[1];
return result;
}
private static readonly Type[] SupportedTypes =
{
typeof(int),
typeof(bool),
typeof(float)
};
}
}