System.Linq.Expressions.Expression.Negate C# (CSharp) Method

Negate() public static method

Creates a UnaryExpression that represents an arithmetic negation operation.
Thrown when is null. Thrown when is not null and the method it represents returns void, is not static (Shared in Visual Basic), or does not take exactly one argument. Thrown when is null and the unary minus operator is not defined for .Type (or its corresponding non-nullable type if it is a nullable value type) is not assignable to the argument type of the method represented by method.
public static Negate ( Expression expression, MethodInfo method ) : UnaryExpression
expression Expression An to set the property equal to.
method System.Reflection.MethodInfo A to set the property equal to.
return UnaryExpression
        public static UnaryExpression Negate(Expression expression, MethodInfo method)
        {
            RequiresCanRead(expression, nameof(expression));
            if (method == null)
            {
                if (expression.Type.IsArithmetic() && !expression.Type.IsUnsignedInt())
                {
                    return new UnaryExpression(ExpressionType.Negate, expression, expression.Type, null);
                }
                return GetUserDefinedUnaryOperatorOrThrow(ExpressionType.Negate, "op_UnaryNegation", expression);
            }
            return GetMethodBasedUnaryOperator(ExpressionType.Negate, expression, method);
        }

Same methods

Expression::Negate ( Expression expression ) : UnaryExpression

Usage Example

Ejemplo n.º 1
0
        public void Method()
        {
            var expected =
                LinqExpression.Negate(
                    LinqExpression.Default(
                        typeof(bool)),
                    typeof(SampleClass).GetMethod(nameof(SampleClass.StaticFunctionWithArgument)));

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

:s
    :unaryExpressionType xt:Negate ;
    :unaryOperand [
        :defaultType [
            :typeName ""System.Boolean"" ;
        ] ;
    ] ;
    :unaryMethod [
        :memberType [
            :typeName ""GraphEngine.Tests.SampleClass, GraphEngine.Tests"" ;
        ] ;
        :memberName ""StaticFunctionWithArgument"" ;
    ] ;
.
";

            ShouldBe(actual, expected);
        }
All Usage Examples Of System.Linq.Expressions.Expression::Negate
Expression