本文整理汇总了C#中ConditionalExpression类的典型用法代码示例。如果您正苦于以下问题:C# ConditionalExpression类的具体用法?C# ConditionalExpression怎么用?C# ConditionalExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConditionalExpression类属于命名空间,在下文中一共展示了ConditionalExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitConditionalExpression
public override void VisitConditionalExpression(ConditionalExpression conditionalExpression)
{
var token = CreateConditionalBlock(conditionalExpression.Condition.GetText());
_tokenList.Add(token);
VisitChildren(token.FalseStatements, conditionalExpression.FalseExpression);
VisitChildren(token.TrueStatements, conditionalExpression.TrueExpression);
}
示例2: UpdateConditional
protected ConditionalExpression UpdateConditional(ConditionalExpression c, Expression test, Expression ifTrue, Expression ifFalse)
{
if (test != c.Test || ifTrue != c.IfTrue || ifFalse != c.IfFalse)
{
return Expression.Condition(test, ifTrue, ifFalse);
}
return c;
}
示例3: VisitConditionalExpression
public override void VisitConditionalExpression (ConditionalExpression conditionalExpression)
{
base.VisitConditionalExpression (conditionalExpression);
if (!conditionalExpression.TrueExpression.Match (conditionalExpression.FalseExpression).Success)
return;
var action = new CodeAction (ctx.TranslateString ("Replace '?:' with branch"),
script => script.Replace (conditionalExpression, conditionalExpression.TrueExpression.Clone ()));
AddIssue (conditionalExpression,
ctx.TranslateString ("'?:' expression has identical true and false branches"), new [] { action });
}
示例4: VisitConditionalExpression
public override void VisitConditionalExpression(ConditionalExpression conditionalExpression)
{
Match m = pattern.Match(conditionalExpression);
if (m.Success) {
var a = m.Get<Expression>("a").Single();
var other = m.Get<Expression>("other").Single();
AddIssue(conditionalExpression, ctx.TranslateString("Convert to '??' expression"), script => {
var expr = new BinaryOperatorExpression (a.Clone (), BinaryOperatorType.NullCoalescing, other.Clone ());
script.Replace (conditionalExpression, expr);
});
}
base.VisitConditionalExpression (conditionalExpression);
}
示例5: GetExpressions
public Tuple<Expression, Expression> GetExpressions (ConditionalExpression cond)
{
var condition = cond.Condition as BinaryOperatorExpression;
var compareNode = condition.Left is NullReferenceExpression ? condition.Right : condition.Left;
if (compareNode.IsMatch (cond.TrueExpression)) {
// a != null ? a : other
return new Tuple<Expression, Expression> (cond.TrueExpression, cond.FalseExpression);
}
// a == null ? other : a
return new Tuple<Expression, Expression> (cond.FalseExpression, cond.TrueExpression);
}
示例6: IsCandidate
public bool IsCandidate (ConditionalExpression node)
{
var condition = node.Condition as BinaryOperatorExpression;
var compareNode = condition.Left is NullReferenceExpression ? condition.Right : condition.Left;
if (compareNode.IsMatch (node.TrueExpression)) {
// a == null ? a : other
if (condition.Operator == BinaryOperatorType.Equality)
return false;
// a != null ? a : other
return compareNode.IsMatch (node.TrueExpression);
} else {
// a == null ? other : a
if (condition.Operator == BinaryOperatorType.Equality)
return compareNode.IsMatch (node.FalseExpression);
// a != null ? other : a
return false;
}
}
示例7: VisitConditionalExpression
public override void VisitConditionalExpression (ConditionalExpression conditionalExpression)
{
var resolveResult = ctx.Resolve (conditionalExpression.Condition);
if (resolveResult.ConstantValue is bool) {
var condition = (bool)resolveResult.ConstantValue;
Expression resultExpr, unreachableExpr;
if (condition) {
resultExpr = conditionalExpression.TrueExpression;
unreachableExpr = conditionalExpression.FalseExpression;
} else {
resultExpr = conditionalExpression.FalseExpression;
unreachableExpr = conditionalExpression.TrueExpression;
}
unreachableNodes.Add (unreachableExpr);
AddIssue (unreachableExpr, ctx.TranslateString ("Remove unreachable code"),
script => script.Replace (conditionalExpression, resultExpr.Clone ()));
}
base.VisitConditionalExpression (conditionalExpression);
}
示例8: Walk
// ConditionalExpression
public override bool Walk(ConditionalExpression node) { return false; }
示例9: Walk
// ConditionalExpression
protected internal virtual bool Walk(ConditionalExpression node) { return true; }
示例10: PostWalk
protected internal virtual void PostWalk(ConditionalExpression node) { }
示例11: Exit
public override void Exit(ConditionalExpression node)
{
level--;
}
示例12: Enter
public override bool Enter(ConditionalExpression node)
{
Print("ConditionalExpression");
level++;
return true;
}
示例13: actionPerformed
/**
* Call back method that must be called as soon as the given <code>
* ConditionalExpression</code> object has been traversed.
*
* @param pConditionalExpression The <code>ConditionalExpression</code>
* object that has just been traversed.
*/
public void actionPerformed(
ConditionalExpression pConditionalExpression)
{
// Nothing to do.
}
示例14: Walk
public override bool Walk(ConditionalExpression node)
{
node.Parent = _currentScope;
return base.Walk(node);
}
示例15: VisitConditionalExpression
public void VisitConditionalExpression(ConditionalExpression condExpr)
{
condExpr.Condition.AcceptWalker(this);
condExpr.TrueExpression.AcceptWalker(this);
condExpr.FalseExpression.AcceptWalker(this);
}