fix: Fixes string set in properties (#779)

This commit is contained in:
Kamron Batman 2021-09-12 12:03:30 -07:00 • committed by GitHub
parent 46fc95ae71
commit c2d8f7d913
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 26 deletions

View file

@ -402,7 +402,7 @@ namespace Server.Gumps
: new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page) : new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page)
); );
} }
else if (IsParsable(type)) else if (IsType(type, OfString) || IsParsable(type))
{ {
from.SendGump(new SetGump(prop, from, m_Object, this)); from.SendGump(new SetGump(prop, from, m_Object, this));
} }

View file

@ -86,7 +86,7 @@ namespace Server
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsParsable(Type t) => public static bool IsParsable(Type t) =>
IsChar(t) || IsString(t) || IsType(t, OfGuid) || IsChar(t) || IsType(t, OfGuid) ||
IsType(t, OfTimeSpan) || IsNumeric(t) || IsDecimal(t) || t.IsDefined(OfParsable, false); IsType(t, OfTimeSpan) || IsNumeric(t) || IsDecimal(t) || t.IsDefined(OfParsable, false);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -126,59 +126,59 @@ namespace Server
try try
{ {
constructed = Enum.Parse(type, value ?? "", true); constructed = Enum.Parse(type, value ?? "", true);
return null;
} }
catch catch
{ {
return "That is not a valid enumeration member."; return "That is not a valid enumeration member.";
} }
} }
else if (IsType(type, OfType))
if (IsType(type, OfType))
{ {
try try
{ {
constructed = AssemblyHandler.FindTypeByName(value); constructed = AssemblyHandler.FindTypeByName(value);
if (constructed == null) return constructed == null ? "No type with that name was found." : null;
{
return "No type with that name was found.";
}
} }
catch catch
{ {
return "No type with that name was found."; return "No type with that name was found.";
} }
} }
else if (value == null)
if (value == null)
{ {
constructed = null; constructed = null;
return null;
} }
else if (value.StartsWithOrdinal("0x") && IsNumeric(type))
if (IsType(type, OfString))
{
constructed = value;
return null;
}
if (value.StartsWithOrdinal("0x") && IsNumeric(type))
{ {
try try
{ {
constructed = Convert.ChangeType(Convert.ToUInt64(value[2..], 16), type); constructed = Convert.ChangeType(Convert.ToUInt64(value[2..], 16), type);
return null;
} }
catch catch
{ {
return "That is not properly formatted."; return "That is not properly formatted.";
} }
} }
else if (IsParsable(type))
if (IsParsable(type))
{ {
try try
{ {
constructed = Parse(type, value); constructed = Parse(type, value);
} return null;
catch
{
return "That is not properly formatted.";
}
}
else
{
try
{
constructed = Convert.ChangeType(value, type);
} }
catch catch
{ {
@ -186,13 +186,20 @@ namespace Server
} }
} }
if (isSerial) // mutate back try
{ {
constructed = (Serial)(constructed ?? Serial.MinusOne); constructed = Convert.ChangeType(value, type);
} if (isSerial) // mutate back
{
constructed = (Serial)(constructed ?? Serial.MinusOne);
}
constructed = constructed; return null;
return null; }
catch
{
return "That is not properly formatted.";
}
} }
} }
} }