private void ReleaseItems(LogicalThreadAffinativeDictionary state) { foreach (var item in state.Values.OfType <IDisposable>()) { item.Dispose(); } state.Clear(); }
private void VerifyScopeOpenness(bool shouldBeOpened, out LogicalThreadAffinativeDictionary state) { state = CallContext.GetData(_dataSlotKey) as LogicalThreadAffinativeDictionary; bool isOpened = state != null; if (isOpened ^ shouldBeOpened) { var getStateInfo = new Func <bool, string>(opened => opened ? "opened" : "closed"); throw new InvalidOperationException(String.Format( "Lifetime scope '{0}' state is '{1}', but should be '{2}'.", Context.FullName, getStateInfo(isOpened), getStateInfo(shouldBeOpened))); } }