/// <summary> /// Removes a <see cref="StateDefinition"/> from of the <see cref="DefinedStates"/> list. /// </summary> /// <param name="state">The <see cref="StateDefinition"/> to be removed. Must not be <see langword="null" />.</param> /// <remarks> /// Also deletes all <see cref="StatefulAccessControlList"/> objects that use only the removed <see cref="StateDefinition"/> /// as a selection criteria. /// </remarks> /// <exception cref="ArgumentException"> /// The <paramref name="state"/> does not exist on the <see cref="StatePropertyDefinition"/>. /// </exception> public void RemoveState(StateDefinition state) { ArgumentUtility.CheckNotNull("state", state); if (!DefinedStatesInternal.Contains(state.ID)) { throw CreateArgumentException("state", "The state '{0}' does not exist on the property '{1}'.", state.Name, Name); } DefinedStatesInternal.Remove(state); foreach (var acl in StatePropertyReferences.SelectMany(r => r.Class.StatefulAccessControlLists).ToList()) { var stateCombinationsContainingRemovedState = acl.StateCombinations.Where(sc => sc.GetStates().Contains(state)).ToList(); foreach (var stateCombination in stateCombinationsContainingRemovedState) { stateCombination.Delete(); if (!acl.StateCombinations.Any()) { acl.Delete(); } } } }