add some convenience functions to InstanceReference
This commit is contained in:
parent
aafd99ab94
commit
0c7abc9a13
@ -15,12 +15,31 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
// along with Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using Mocha.Core;
|
||||||
|
|
||||||
public class InstanceReference
|
public class InstanceReference
|
||||||
{
|
{
|
||||||
|
public static IEnumerable<InstanceHandle> GetHandles(IEnumerable<InstanceReference> 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)
|
public InstanceReference(Guid globalIdentifier)
|
||||||
{
|
{
|
||||||
GlobalIdentifier = globalIdentifier;
|
GlobalIdentifier = globalIdentifier;
|
||||||
}
|
}
|
||||||
|
public InstanceKey InstanceKey { get; }
|
||||||
public Guid GlobalIdentifier { get; }
|
public Guid GlobalIdentifier { get; }
|
||||||
|
|
||||||
public static bool operator==(InstanceReference left, InstanceReference right)
|
public static bool operator==(InstanceReference left, InstanceReference right)
|
||||||
@ -44,4 +63,13 @@ public class InstanceReference
|
|||||||
{
|
{
|
||||||
return GlobalIdentifier.GetHashCode();
|
return GlobalIdentifier.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InstanceHandle GetHandle(Oms oms)
|
||||||
|
{
|
||||||
|
if (GlobalIdentifier == Guid.Empty)
|
||||||
|
{
|
||||||
|
return oms.GetInstance(InstanceKey);
|
||||||
|
}
|
||||||
|
return oms.GetInstance(GlobalIdentifier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user