public bool Join(IContractPointerOwner <T> owner) { if (!this.IsActive) { return(false); } // TODO: This is not great but I can't think of how else to do this. // TODO: Seriously, figure out a better way to do this at some point. // TODO: Please. if (owner is StrongContractPointerOwner <T> strongOwner) { if (this.strongOwners_.Add(strongOwner)) { strongOwner.JoinBackdoor_(this); return(true); } } else { var weakOwner = (owner as WeakContractPointerOwner <T>) !; if (this.weakOwners_.Add(weakOwner)) { weakOwner.JoinBackdoor_(this); return(true); } } return(false); }
public IClosedContractPointer <T> FormClosedWith( T value, IContractPointerOwner <T> other, params IContractPointerOwner <T>[] additional) { var owners = new HashSet <IContractPointerOwner <T> > { this, other }; owners.UnionWith(additional); return(new ContractPointerOwnerImpl <T> .ClosedContractPointer( value, owners.ToArray())); }
/// <summary> /// Inaccessible from IContractPointer types. /// </summary> public void BreakWith(IContractPointerOwner <T> owner) { bool removed; if (owner is IStrongContractPointerOwner <T> strongOwner) { removed = this.strongOwners_.Remove(strongOwner); } else { var weakOwner = (owner as IWeakContractPointerOwner <T>) !; removed = this.weakOwners_.Remove(weakOwner); } if (removed && this.strongOwners_.Count == 0) { this.Break(); } }
public static void AssertContents <T>(IContractPointerOwner <T> set, params IContractPointer <T>[] contracts) { CollectionAssert.AreEqual(contracts, set.Contracts.ToArray()); }
public static void AssertEmpty <T>(IContractPointerOwner <T> set) { AssertContents(set); }