public StateDefinition GetState(string name) { ArgumentUtility.CheckNotNullOrEmpty("name", name); return(DefinedStatesInternal.Single( s => s.Name == name, () => CreateArgumentException("name", "The state '{0}' is not defined for the property '{1}'.", name, Name))); }
/// <summary> /// Adds a <see cref="StateDefinition"/> to the <see cref="DefinedStates"/> list. /// </summary> /// <param name="state">The <see cref="StateDefinition"/> to be added. Must not be <see langword="null" />.</param> /// <exception cref="ArgumentException"> /// The <paramref name="state"/> already exists on the <see cref="StatePropertyDefinition"/>. /// </exception> public void AddState(StateDefinition state) { ArgumentUtility.CheckNotNull("state", state); if (ContainsState(state.Name)) { throw CreateArgumentException("state", "A state with the name '{0}' was already added to the property '{1}'.", state.Name, Name); } if (ContainsState(state.Value)) { throw CreateArgumentException("state", "A state with the value {0} was already added to the property '{1}'.", state.Value, Name); } DefinedStatesInternal.Add(state); }
/// <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(); } } } }
public bool ContainsState(int stateValue) { return(DefinedStatesInternal.Any(s => s.Value == stateValue)); }
public StateDefinition GetState(int stateValue) { return(DefinedStatesInternal.Single( s => s.Value == stateValue, () => CreateArgumentException("stateValue", "A state with the value {0} is not defined for the property '{1}'.", stateValue, Name))); }
public bool ContainsState(string name) { ArgumentUtility.CheckNotNullOrEmpty("name", name); return(DefinedStatesInternal.Any(s => s.Name == name)); }