diff --git a/Runtime/Extensions.cs b/Runtime/Extensions.cs new file mode 100644 index 0000000..f87fae2 --- /dev/null +++ b/Runtime/Extensions.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; + +namespace TNRD +{ + public static class Extensions + { + /// + /// Checks to see if the containing value is valid and returns it through the out parameter if so + /// + /// + /// The containing value, if valid + /// True if the containing value is valid, false if not + public static bool IsDefined( + this SerializableInterface serializableInterface, + out TInterface value + ) + where TInterface : class + { + if (serializableInterface == null) + { + value = default; + return false; + } + + if (EqualityComparer.Default.Equals(serializableInterface.Value, default)) + { + value = default; + return false; + } + + value = serializableInterface.Value; + return true; + } + + /// + public static bool TryGetValue( + this SerializableInterface serializableInterface, + out TInterface value + ) + where TInterface : class + { + return IsDefined(serializableInterface, out value); + } + } +} diff --git a/Runtime/Extensions.cs.meta b/Runtime/Extensions.cs.meta new file mode 100644 index 0000000..c890069 --- /dev/null +++ b/Runtime/Extensions.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 77acf133582b451fa1cea3bb60b48dc6 +timeCreated: 1659443598 \ No newline at end of file