Unstable v0.15.17.0 (Hex is out of town edition)
This commit is contained in:
@@ -30,12 +30,20 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
public override bool TryGet(out T t) { t = Value; return true; }
|
||||
public override bool TryGet(out U u) { u = default(U); return false; }
|
||||
public override bool TryGet(out U u) { u = default; return false; }
|
||||
|
||||
public override bool TryCast<V>(out V v)
|
||||
{
|
||||
if (Value is V result) { v = result; return true; }
|
||||
else { v = default(V); return false; }
|
||||
if (Value is V result)
|
||||
{
|
||||
v = result;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
v = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,13 +58,21 @@ namespace Barotrauma
|
||||
return Value.ToString();
|
||||
}
|
||||
|
||||
public override bool TryGet(out T t) { t = default(T); return false; }
|
||||
public override bool TryGet(out T t) { t = default; return false; }
|
||||
public override bool TryGet(out U u) { u = Value; return true; }
|
||||
|
||||
public override bool TryCast<V>(out V v)
|
||||
{
|
||||
if (Value is V result) { v = result; return true; }
|
||||
else { v = default(V); return false; }
|
||||
if (Value is V result)
|
||||
{
|
||||
v = result;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
v = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -534,6 +535,16 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
// Enum.HasFlag() sucks
|
||||
public static bool IsBitSet<T>(this T self, T bit) where T : struct, Enum
|
||||
{
|
||||
// This uses Unsafe.As for performance reasons, as
|
||||
// C# will otherwise not allow a T -> int cast
|
||||
// without first casting to object, which would make
|
||||
// this not any better than Enum.HasFlag
|
||||
return (Unsafe.As<T, int>(ref self) & Unsafe.As<T, int>(ref bit)) != 0;
|
||||
}
|
||||
|
||||
public static string ByteArrayToString(byte[] ba)
|
||||
{
|
||||
StringBuilder hex = new StringBuilder(ba.Length * 2);
|
||||
|
||||
Reference in New Issue
Block a user