private FoldableObjectToken getTokenOf(IFoldableObject obj) { foreach (var info in _activeObjects) { if (info.Target == obj) return info; } foreach (var info in _packedObjects) { if (info.Target == obj) return info; } return null; }
public FoldableLockObject(IFoldableObject target) { this.Target = target; }
public void Unregister(IFoldableObject obj) { if (!Contains(obj)) return; obj.StateChanged -= Obj_StateChanged; pop(getTokenOf(obj)); }
public void Register (IFoldableObject obj) { if (Contains(obj)) return; push( new FoldableObjectToken(obj)); obj.StateChanged += Obj_StateChanged; }
public bool Contains(IFoldableObject obj) { return getTokenOf(obj) != null; }
public FoldableObjectToken(IFoldableObject obj) { this.Target = obj; }
private void Obj_StateChanged(IFoldableObject obj, EventArgs e) { if (obj.CurrentState == FoldableObjectState.NotRegistered) { throw new InvalidOperationException(); } var info = getTokenOf(obj); pop(info); push(info); }