Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Runtime/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;

namespace TNRD
{
public static class Extensions
{
/// <summary>
/// Checks to see if the containing value is valid and returns it through the out parameter if so
/// </summary>
/// <param name="serializableInterface"></param>
/// <param name="value">The containing value, if valid</param>
/// <returns>True if the containing value is valid, false if not</returns>
public static bool IsDefined<TInterface>(
this SerializableInterface<TInterface> serializableInterface,
out TInterface value
)
where TInterface : class
{
if (serializableInterface == null)
{
value = default;
return false;
}

if (EqualityComparer<TInterface>.Default.Equals(serializableInterface.Value, default))
{
value = default;
return false;
}

value = serializableInterface.Value;
return true;
}

/// <inheritdoc cref="IsDefined{TInterface}"/>
public static bool TryGetValue<TInterface>(
this SerializableInterface<TInterface> serializableInterface,
out TInterface value
)
where TInterface : class
{
return IsDefined(serializableInterface, out value);
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Extensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.