/// <summary> /// Create a new <see cref="UserEntityPermissionTuple"/>. /// </summary> /// <param name="userRuleSet"> /// An object that represents a set of rules. /// </param> /// <param name="entityId"> /// The ID of the entity. /// </param> /// <param name="permissionIds"> /// The permissions. This cannot be null. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="permissionIds"/> cannot be null. /// </exception> /// <seealso cref="UserRuleSet"/> /// <seealso cref="EntityId"/> /// <seealso cref="PermissionIds"/> public RuleSetEntityPermissionTuple(UserRuleSet userRuleSet, long entityId, IEnumerable <long> permissionIds) { if (permissionIds == null) { throw new ArgumentNullException("permissionIds"); } UserRuleSet = userRuleSet; EntityId = entityId; PermissionIds = (permissionIds.OrderBy(x => x)).ToArray(); _hashCode = GenerateHashCode(UserRuleSet, EntityId, PermissionIds); }
/// <summary> /// Create the hash code. /// </summary> /// <returns></returns> internal static int GenerateHashCode(UserRuleSet userRuleSet, long entityId, IEnumerable <long> permissionIds) { if (permissionIds == null) { throw new ArgumentNullException("permissionIds"); } int hashCode; unchecked { hashCode = 17; hashCode = ( int )(hashCode * 92821 + EqualityComparer <UserRuleSet> .Default.GetHashCode(userRuleSet)); hashCode = ( int )(hashCode * 92821 + entityId); hashCode = permissionIds.Aggregate(hashCode, (current, permissionId) => current * 92821 + ( int )permissionId); } return(hashCode); }