Fixed XML encoding, add equality comparisons to Optional<T>

This commit is contained in:
Max 2021-05-05 13:22:18 -05:00
parent f421743b08
commit fb443cdf42
3 changed files with 34 additions and 1 deletions

View File

@ -1,4 +1,6 @@
namespace RobloxFiles.DataTypes
using System;
namespace RobloxFiles.DataTypes
{
// Optional represents a value that can be explicitly
// marked as an optional variant to a specified type.
@ -19,6 +21,29 @@
return Value?.ToString() ?? "null";
}
public override int GetHashCode()
{
if (HasValue)
return Value.GetHashCode();
var T = typeof(T);
return T.GetHashCode();
}
public override bool Equals(object obj)
{
if (!(obj is Optional<T> optional))
return false;
if (HasValue != optional.HasValue)
return false;
if (HasValue)
return Value.Equals(optional.Value);
return true; // Both have no value.
}
public static implicit operator T(Optional<T> optional)
{
if (optional.HasValue)

Binary file not shown.

View File

@ -644,6 +644,14 @@ namespace RobloxFiles
xmlToken = "CoordinateFrame";
break;
}
case "Optional`1":
{
// TODO: If more optional types are added,
// this needs disambiguation.
xmlToken = "OptionalCoordinateFrame";
break;
}
}
if (!props.ContainsKey(fieldName))