ReferenceEqual() public static method

Creates a BinaryExpression that represents a reference equality comparison.
public static ReferenceEqual ( Expression left, Expression right ) : BinaryExpression
left Expression An to set the property equal to.
right Expression An to set the property equal to.
return BinaryExpression
コード例 #1
0
        // Helper that is used when re-eval of LHS is safe.
        private Expression ByValParameterTypeEqual(ParameterExpression value)
        {
            Expression getType = Expression.Call(value, typeof(object).GetMethod("GetType"));

            // In remoting scenarios, obj.GetType() can return an interface.
            // But JIT32's optimized "obj.GetType() == typeof(ISomething)" codegen,
            // causing it to always return false.
            // We workaround this optimization by generating different, less optimal IL
            // if TypeOperand is an interface.
            if (_typeOperand.GetTypeInfo().IsInterface)
            {
                var temp = Expression.Parameter(typeof(Type));
                getType = Expression.Block(new[] { temp }, Expression.Assign(temp, getType), temp);
            }

            // We use reference equality when comparing to null for correctness
            // (don't invoke a user defined operator), and reference equality
            // on types for performance (so the JIT can optimize the IL).
            return(Expression.AndAlso(
                       Expression.ReferenceNotEqual(value, Expression.Constant(null)),
                       Expression.ReferenceEqual(
                           getType,
                           Expression.Constant(_typeOperand.GetNonNullableType(), typeof(Type))
                           )
                       ));
        }
コード例 #2
0
        public void ReferenceEquals()
        {
            var expected =
                LinqExpression.ReferenceEqual(
                    LinqExpression.Parameter(
                        typeof(object)),
                    LinqExpression.Parameter(
                        typeof(object)));

            var actual = $@"
@prefix : <http://example.com/> .

:s
    a :ReferenceEqual ;
    :binaryLeft [
        :parameterType [
            :typeName ""System.Object"" ;
        ]
    ] ;
    :binaryRight [
        :parameterType [
            :typeName ""System.Object"" ;
        ] ;
    ] ;
.
";

            ShouldBe(actual, expected);
        }
コード例 #3
0
        public void ReferenceEqual()
        {
            var expression =
                LinqExpression.ReferenceEqual(
                    LinqExpression.Parameter(
                        typeof(object)),
                    LinqExpression.Parameter(
                        typeof(object)));

            ShouldRoundrip(expression);
        }
コード例 #4
0
 public BinaryExpression Update(Expression left, LambdaExpression conversion, Expression right)
 {
     if (((left == this.Left) && (right == this.Right)) && (conversion == this.Conversion))
     {
         return(this);
     }
     if (!this.IsReferenceComparison)
     {
         return(Expression.MakeBinary(this.NodeType, left, right, this.IsLiftedToNull, this.Method, conversion));
     }
     if (this.NodeType == ExpressionType.Equal)
     {
         return(Expression.ReferenceEqual(left, right));
     }
     return(Expression.ReferenceNotEqual(left, right));
 }