本文整理汇总了C#中IExpression.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# IExpression.Equals方法的具体用法?C# IExpression.Equals怎么用?C# IExpression.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IExpression
的用法示例。
在下文中一共展示了IExpression.Equals方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: And
/// <summary>Optimizations: f&&X->f, t&&X->X, X&&X->X, X&&!X->f</summary>
public virtual IExpression And(IExpression left, IExpression right)
{
if (left.Equals(BoolConstExpression.False) || right.Equals(BoolConstExpression.False
))
{
return BoolConstExpression.False;
}
if (left.Equals(BoolConstExpression.True))
{
return right;
}
if (right.Equals(BoolConstExpression.True))
{
return left;
}
if (left.Equals(right))
{
return left;
}
if (Negatives(left, right))
{
return BoolConstExpression.False;
}
return new AndExpression(left, right);
}
示例2: Not
/// <summary>Optimizations: !(Bool)->(!Bool), !!X->X, !(X==Bool)->(X==!Bool)
/// </summary>
public virtual IExpression Not(IExpression expr)
{
if (expr.Equals(BoolConstExpression.True))
{
return BoolConstExpression.False;
}
if (expr.Equals(BoolConstExpression.False))
{
return BoolConstExpression.True;
}
if (expr is NotExpression)
{
return ((NotExpression)expr).Expr();
}
if (expr is ComparisonExpression)
{
ComparisonExpression cmpExpr = (ComparisonExpression)expr;
if (cmpExpr.Right() is ConstValue)
{
ConstValue rightConst = (ConstValue)cmpExpr.Right();
if (rightConst.Value() is bool)
{
bool boolVal = (bool)rightConst.Value();
// new Boolean() instead of Boolean.valueOf() for .NET conversion
return new ComparisonExpression(cmpExpr.Left(), new ConstValue(!boolVal), cmpExpr
.Op());
}
}
}
return new NotExpression(expr);
}
示例3: CheckBoolean
private IExpression CheckBoolean(IExpression cmp, IExpression trueExpr, IExpression
falseExpr)
{
if (cmp is BoolConstExpression)
{
return null;
}
if (trueExpr is BoolConstExpression)
{
bool leftNegative = trueExpr.Equals(BoolConstExpression.False);
if (!leftNegative)
{
return Or(cmp, falseExpr);
}
else
{
return And(Not(cmp), falseExpr);
}
}
if (falseExpr is BoolConstExpression)
{
bool rightNegative = falseExpr.Equals(BoolConstExpression.False);
if (!rightNegative)
{
return And(cmp, trueExpr);
}
else
{
return Or(Not(cmp), falseExpr);
}
}
if (cmp is NotExpression)
{
cmp = ((NotExpression)cmp).Expr();
IExpression swap = trueExpr;
trueExpr = falseExpr;
falseExpr = swap;
}
if (trueExpr is OrExpression)
{
OrExpression orExpr = (OrExpression)trueExpr;
IExpression orLeft = orExpr.Left();
IExpression orRight = orExpr.Right();
if (falseExpr.Equals(orRight))
{
IExpression swap = orRight;
orRight = orLeft;
orLeft = swap;
}
if (falseExpr.Equals(orLeft))
{
return Or(orLeft, And(cmp, orRight));
}
}
if (falseExpr is AndExpression)
{
AndExpression andExpr = (AndExpression)falseExpr;
IExpression andLeft = andExpr.Left();
IExpression andRight = andExpr.Right();
if (trueExpr.Equals(andRight))
{
IExpression swap = andRight;
andRight = andLeft;
andLeft = swap;
}
if (trueExpr.Equals(andLeft))
{
return And(andLeft, Or(cmp, andRight));
}
}
return null;
}
示例4: HasVar
/// <summary>
/// Checks the <paramref name="expression"/> parameter has <paramref name="arg"/>.
/// </summary>
/// <param name="expression">A expression that is checked.</param>
/// <param name="arg">A variable that can be contained in the expression.</param>
/// <returns>true if <paramref name="expression"/> has <paramref name="arg"/>; otherwise, false.</returns>
public static bool HasVar(IExpression expression, Variable arg)
{
var bin = expression as BinaryExpression;
if (bin != null)
return HasVar(bin.Left, arg) || HasVar(bin.Right, arg);
var un = expression as UnaryExpression;
if (un != null)
return HasVar(un.Argument, arg);
var paramExp = expression as DifferentParametersExpression;
if (paramExp != null)
return paramExp.Arguments.Any(e => HasVar(e, arg));
return expression is Variable && expression.Equals(arg);
}