예제 #1
0
 /// <summary>
 ///     Gets the hash code for the key.
 /// </summary>
 /// <returns>
 ///     The hash code for the key.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = _expressionEqualityComparer.GetHashCode(_query);
         hashCode = (hashCode * 397) ^ _model.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)_queryTrackingBehavior;
         hashCode = (hashCode * 397) ^ _async.GetHashCode();
         return(hashCode);
     }
 }
        public void Member_init_expressions_are_compared_correctly()
        {
            var expressionComparer = new ExpressionEqualityComparer();

            var addMethod = typeof(List <string>).GetTypeInfo().GetDeclaredMethod("Add");

            var bindingMessages = Expression.ListBind(
                typeof(Node).GetProperty("Messages"),
                Expression.ElementInit(addMethod, Expression.Constant("Constant1"))
                );

            var bindingDescriptions = Expression.ListBind(
                typeof(Node).GetProperty("Descriptions"),
                Expression.ElementInit(addMethod, Expression.Constant("Constant2"))
                );

            Expression e1 = Expression.MemberInit(
                Expression.New(typeof(Node)),
                new List <MemberBinding>
            {
                bindingMessages
            }
                );

            Expression e2 = Expression.MemberInit(
                Expression.New(typeof(Node)),
                new List <MemberBinding>
            {
                bindingMessages,
                bindingDescriptions
            }
                );

            Assert.NotEqual(expressionComparer.GetHashCode(e1), expressionComparer.GetHashCode(e2));
            Assert.False(expressionComparer.Equals(e1, e2));
            Assert.Equal(expressionComparer.GetHashCode(e1), expressionComparer.GetHashCode(e1));
            Assert.True(expressionComparer.Equals(e1, e1));
        }