/// <summary> /// Creates a structurally equivalent member binding index from a given binding index. /// </summary> /// <param name="bindingIndex">The binding index to copy the structure from.</param> /// <returns>A structurally equivalent copy of the given binding index.</returns> public static IStonBindingIndex Copy(IStonBindingIndex bindingIndex) { if (bindingIndex == null) { throw new ArgumentNullException("bindingIndex"); } return(new StonBindingIndex(bindingIndex)); }
// writes a binding index private void WriteBindingKey(StonTokenWriter writer, IStonBindingIndex bindingKey) { if (bindingKey.Parameters == null) { throw new StonException("A member binding index cannot have non-existing parameters."); } writer.Write('['); WriteSequence(writer, bindingKey.Parameters, WriteEntity); writer.Write(']'); }
/// <summary> /// Determines whether two binding indices are equivalent by comparing corresponding entities. /// </summary> /// <param name="x">The first binding indices to compare.</param> /// <param name="y">The second binding indices to compare.</param> /// <returns>True when binding indices are equivalent, false otherwise.</returns> public bool Equals(IStonBindingIndex x, IStonBindingIndex y) { if (x == y) { return(true); } else if (x == null || y == null) { return(false); } return(x.Parameters.SequenceEqual(y.Parameters, IndexParameterComparer)); }
/// <summary> /// Returns a hash code for a given binding index. /// </summary> /// <param name="obj">The binding index to get a hash code of.</param> /// <returns>The hash code for the binding index.</returns> public int GetHashCode(IStonBindingIndex obj) { if (obj == null) { return(0); } unchecked { int result = 11; foreach (var parameter in obj.Parameters) { result = result * 31 + IndexParameterComparer.GetHashCode(parameter); } return(result); } }
/// <summary> /// Checks the validity of a given STON member binding index. /// </summary> /// <param name="bindingKey">The member binding index to check the validity of.</param> public static void ValidateBindingKey(IStonBindingIndex bindingKey) { if (bindingKey == null) { throw new ArgumentNullException("bindingKey"); } if (bindingKey.Parameters == null || !bindingKey.Parameters.Any()) { throw new StonException("A member binding index must be neither non-existing nor empty."); } foreach (var parameter in bindingKey.Parameters) { if (parameter == null) { throw new StonException("A member binding index cannot have non-existing index parameters."); } } }
/// <summary> /// Creates a structurally equivalent member binding index from a given binding index. /// </summary> /// <param name="bindingIndex">The binding index to copy the structure from.</param> public StonBindingIndex(IStonBindingIndex bindingIndex) : this(bindingIndex.Parameters) { }