Skip to content

Commit a51f7b6

Browse files
authored
Merge pull request #49 from Thundernerd/feature/getting_value
2 parents ef4cf17 + 1154dbb commit a51f7b6

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Runtime/Extensions.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Collections.Generic;
2+
3+
namespace TNRD
4+
{
5+
public static class Extensions
6+
{
7+
/// <summary>
8+
/// Checks to see if the containing value is valid and returns it through the out parameter if so
9+
/// </summary>
10+
/// <param name="serializableInterface"></param>
11+
/// <param name="value">The containing value, if valid</param>
12+
/// <returns>True if the containing value is valid, false if not</returns>
13+
public static bool IsDefined<TInterface>(
14+
this SerializableInterface<TInterface> serializableInterface,
15+
out TInterface value
16+
)
17+
where TInterface : class
18+
{
19+
if (serializableInterface == null)
20+
{
21+
value = default;
22+
return false;
23+
}
24+
25+
if (EqualityComparer<TInterface>.Default.Equals(serializableInterface.Value, default))
26+
{
27+
value = default;
28+
return false;
29+
}
30+
31+
value = serializableInterface.Value;
32+
return true;
33+
}
34+
35+
/// <inheritdoc cref="IsDefined{TInterface}"/>
36+
public static bool TryGetValue<TInterface>(
37+
this SerializableInterface<TInterface> serializableInterface,
38+
out TInterface value
39+
)
40+
where TInterface : class
41+
{
42+
return IsDefined(serializableInterface, out value);
43+
}
44+
}
45+
}

Runtime/Extensions.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)