Changed behavior for empty string Color properties

When an unset Color property was parsed, an exception was thrown. This exception was moved into TryParse. Now, the Color can be null.
This commit is contained in:
differenceclouds 2024-11-12 20:46:44 -05:00
parent 8dba9e81a0
commit c83c8c7be9

View file

@ -40,7 +40,8 @@ public class Color : IParsable<Color>, IEquatable<Color>
public static Color Parse(string s, IFormatProvider provider) public static Color Parse(string s, IFormatProvider provider)
{ {
_ = TryParse(s, provider, out var result); _ = TryParse(s, provider, out var result);
return result ?? throw new FormatException($"Invalid format for TiledColor: {s}"); //return result ?? throw new FormatException($"Invalid format for TiledColor: {s}");
return result; //let result be null
} }
/// <summary> /// <summary>
@ -62,6 +63,8 @@ public class Color : IParsable<Color>, IEquatable<Color>
// Format: #RRGGBB or #AARRGGBB // Format: #RRGGBB or #AARRGGBB
if (s is null || (s.Length != 7 && s.Length != 9) || s[0] != '#') if (s is null || (s.Length != 7 && s.Length != 9) || s[0] != '#')
{ {
if (s.Length > 1)
throw new FormatException($"Invalid format for TiledColor: {s}");
result = default; result = default;
return false; return false;
} }