fix: Makes guid settable. Cleans up type conversions (#765)
* Marks GUID a parsable type * Cleans up type conversions
This commit is contained in:
parent
1916dc00cb
commit
04b5a6c609
6 changed files with 155 additions and 416 deletions
|
|
@ -13,8 +13,6 @@ namespace Server.Commands
|
|||
{
|
||||
public static class Add
|
||||
{
|
||||
private static readonly object[] m_ParseArgs = new object[1];
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("Tile", AccessLevel.GameMaster, Tile_OnCommand);
|
||||
|
|
@ -245,7 +243,7 @@ namespace Server.Commands
|
|||
for (int i = 0, a = 0; i < paramList.Length; i++)
|
||||
{
|
||||
var param = paramList[i];
|
||||
var value = ParseValue(param.ParameterType, a < args.Length ? args[a++] : null);
|
||||
TryParse(param.ParameterType, a < args.Length ? args[a++] : null, out var value);
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
|
|
@ -264,56 +262,6 @@ namespace Server.Commands
|
|||
return values;
|
||||
}
|
||||
|
||||
public static object ParseValue(Type type, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (IsEnum(type))
|
||||
{
|
||||
return Enum.Parse(type, value, true);
|
||||
}
|
||||
|
||||
if (IsType(type))
|
||||
{
|
||||
return AssemblyHandler.FindTypeByName(value);
|
||||
}
|
||||
|
||||
if (IsParsable(type))
|
||||
{
|
||||
return ParseParsable(type, value);
|
||||
}
|
||||
|
||||
object obj = value;
|
||||
|
||||
if (value.StartsWithOrdinal("0x"))
|
||||
{
|
||||
if (IsSignedNumeric(type))
|
||||
{
|
||||
obj = Convert.ToInt64(value[2..], 16);
|
||||
}
|
||||
else if (IsUnsignedNumeric(type))
|
||||
{
|
||||
obj = Convert.ToUInt64(value[2..], 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = Convert.ToInt32(value[2..], 16);
|
||||
}
|
||||
}
|
||||
|
||||
if (obj == null && !type.IsValueType)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Convert.ChangeType(obj, type);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEntity Build(
|
||||
Mobile from, ConstructorInfo ctor, object[] values, string[,] props,
|
||||
PropertyInfo[] realProps, ref bool sendError
|
||||
|
|
@ -735,21 +683,6 @@ namespace Server.Commands
|
|||
InternalAvg_OnCommand(e, true);
|
||||
}
|
||||
|
||||
public static bool IsEnum(Type type) => type.IsSubclassOf(OfEnum);
|
||||
|
||||
public static bool IsType(Type type) => type == OfType || type.IsSubclassOf(OfType);
|
||||
|
||||
public static bool IsParsable(Type type) => type.IsDefined(OfParsable, false);
|
||||
|
||||
public static object ParseParsable(Type type, string value)
|
||||
{
|
||||
var method = type.GetMethod("Parse", ParseTypes);
|
||||
|
||||
m_ParseArgs[0] = value;
|
||||
|
||||
return method?.Invoke(null, m_ParseArgs);
|
||||
}
|
||||
|
||||
private enum TileZType
|
||||
{
|
||||
Start,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue