From 0c7abc9a13b9bd28933220c2ed04a0abcf24e76e Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 30 Sep 2025 08:39:23 -0400 Subject: [PATCH] add some convenience functions to InstanceReference --- .../src/lib/Mocha.Core/InstanceReference.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mocha-dotnet/src/lib/Mocha.Core/InstanceReference.cs b/mocha-dotnet/src/lib/Mocha.Core/InstanceReference.cs index d625429..9e9fbdf 100644 --- a/mocha-dotnet/src/lib/Mocha.Core/InstanceReference.cs +++ b/mocha-dotnet/src/lib/Mocha.Core/InstanceReference.cs @@ -15,12 +15,31 @@ // You should have received a copy of the GNU General Public License // along with Mocha.NET. If not, see . +using Mocha.Core; + public class InstanceReference { + public static IEnumerable GetHandles(IEnumerable irs, Oms oms) + { + foreach (InstanceReference ir in irs) + { + yield return ir.GetHandle(oms); + } + } + public InstanceReference(InstanceKey instanceKey) + { + InstanceKey = instanceKey; + } + public InstanceReference(InstanceKey instanceKey, Guid globalIdentifier) + { + InstanceKey = instanceKey; + GlobalIdentifier = globalIdentifier; + } public InstanceReference(Guid globalIdentifier) { GlobalIdentifier = globalIdentifier; } + public InstanceKey InstanceKey { get; } public Guid GlobalIdentifier { get; } public static bool operator==(InstanceReference left, InstanceReference right) @@ -44,4 +63,13 @@ public class InstanceReference { return GlobalIdentifier.GetHashCode(); } + + public InstanceHandle GetHandle(Oms oms) + { + if (GlobalIdentifier == Guid.Empty) + { + return oms.GetInstance(InstanceKey); + } + return oms.GetInstance(GlobalIdentifier); + } } \ No newline at end of file