Use explicit Optional<T> type for OptionalCFrame.

This commit is contained in:
Max
2021-05-05 13:06:20 -05:00
parent 0e7f9030c8
commit f421743b08
10 changed files with 69 additions and 14 deletions

35
DataTypes/Optional.cs Normal file
View File

@ -0,0 +1,35 @@
namespace RobloxFiles.DataTypes
{
// Optional represents a value that can be explicitly
// marked as an optional variant to a specified type.
// In practice this is used for OptionalCFrame.
public struct Optional<T>
{
public T Value;
public bool HasValue => (Value != null);
public Optional(T value)
{
Value = value;
}
public override string ToString()
{
return Value?.ToString() ?? "null";
}
public static implicit operator T(Optional<T> optional)
{
if (optional.HasValue)
return optional.Value;
return default(T);
}
public static implicit operator Optional<T>(T value)
{
return new Optional<T>(value);
}
}
}