Fixed XML encoding, add equality comparisons to Optional<T>
This commit is contained in:
parent
f421743b08
commit
fb443cdf42
@ -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.
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user