本文整理汇总了C#中BinaryExpressionSyntax.GetLeadingTrivia方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpressionSyntax.GetLeadingTrivia方法的具体用法?C# BinaryExpressionSyntax.GetLeadingTrivia怎么用?C# BinaryExpressionSyntax.GetLeadingTrivia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryExpressionSyntax
的用法示例。
在下文中一共展示了BinaryExpressionSyntax.GetLeadingTrivia方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerformAction
static Document PerformAction(Document document, SyntaxNode root, BinaryExpressionSyntax bop)
{
var nodeToReplace = bop.IsParentKind(SyntaxKind.ParenthesizedExpression) ? bop.Parent : bop;
var castExpr = (ExpressionSyntax)SyntaxFactory.CastExpression(bop.Right as TypeSyntax, CSharpUtil.AddParensIfRequired(bop.Left.WithoutLeadingTrivia().WithoutTrailingTrivia())).WithLeadingTrivia(bop.GetLeadingTrivia()).WithTrailingTrivia(bop.GetTrailingTrivia());
var newRoot = root.ReplaceNode((SyntaxNode)nodeToReplace, castExpr);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:8,代码来源:ReplaceSafeCastWithDirectCastCodeRefactoringProvider.cs
示例2: VisitBinaryExpression
public override SyntaxNode VisitBinaryExpression(BinaryExpressionSyntax node)
{
Tristate leftState = _expressionEvaluator.EvaluateExpression(node.Left);
Tristate rightState = _expressionEvaluator.EvaluateExpression(node.Right);
var left = (ExpressionSyntax)node.Left.Accept(this);
var right = (ExpressionSyntax)node.Right.Accept(this);
if (node.Left != left)
{
node = node.WithLeft(left);
}
if (node.Right != right)
{
node = node.WithRight(right);
}
if (leftState != Tristate.Varying && rightState != Tristate.Varying)
{
return node;
}
ExpressionSyntax newExpression = null;
if (node.Kind() == SyntaxKind.LogicalAndExpression)
{
if (leftState == Tristate.True)
{
// true && varying == varying
newExpression = right;
}
else if (rightState == Tristate.True)
{
// varying && true == varying
newExpression = left;
}
}
else if (node.Kind() == SyntaxKind.LogicalOrExpression)
{
if (leftState == Tristate.False)
{
// false || varying == varying
newExpression = right;
}
else if (rightState == Tristate.False)
{
// varying || false == varying
newExpression = left;
}
}
if (newExpression != null)
{
return newExpression
.WithLeadingTrivia(node.GetLeadingTrivia())
.WithTrailingTrivia(node.GetTrailingTrivia());
}
return node;
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-codeformatter-dotnet,代码行数:61,代码来源:PreprocessorExpressionSimplifier.cs
示例3: TraverseBinaryExpression
private Method TraverseBinaryExpression(BinaryExpressionSyntax bes)
{
var variables = from aVariable in bes.ChildNodes().OfType<IdentifierNameSyntax>() select aVariable;
Method retMethod = new Method();
if (bes.HasLeadingTrivia)
{
SetOuterComments(retMethod, bes.GetLeadingTrivia().ToFullString());
}
if (bes.HasTrailingTrivia)
{
SetInnerComments(retMethod, bes.GetTrailingTrivia().ToFullString());
}
//Casting on the back end....ex:
// abc = def as double ------- def as double is the binary expression
if (bes.OperatorToken.IsKind(SyntaxKind.AsKeyword))
{
if (bes.Left is IdentifierNameSyntax)
{
IdentifierNameSyntax ins = bes.Left as IdentifierNameSyntax;
Variables tempVar = new Variables();
tempVar.Name = ins.Identifier.ValueText;
if (bes.Right is PredefinedTypeSyntax)
{
PredefinedTypeSyntax pts = bes.Right as PredefinedTypeSyntax;
Model.Type tempType = new Model.Type();
tempType.Name = pts.ToString();
tempType.IsKnownType = true;
tempType.IsNotUserDefined = true;
tempVar.Type = tempType;
}
retMethod.AccessedVariables.Add(tempVar);
}
else if (bes.Left is MemberAccessExpressionSyntax)
{
MemberAccessExpressionSyntax maes = bes.Left as MemberAccessExpressionSyntax;
Variables tempVar = new Variables();
tempVar.Name = maes.ToString();
tempVar.IsReferenced = true;
retMethod.AccessedVariables.Add(tempVar);
}
}
else
{
foreach (IdentifierNameSyntax ins in variables)
{
//TODO put a bp here and test if this adds method names (bad) or just var names(good)
Variables vars = new Variables();
vars.Name = ins.Identifier.ValueText;
vars.IsReferenced = true;
retMethod.AccessedVariables.Add(vars);
//TODO variable types
}
var binaryExprs = from aBinaryExpr in bes.ChildNodes().OfType<BinaryExpressionSyntax>() select aBinaryExpr;
foreach (BinaryExpressionSyntax bes2 in binaryExprs)
{
Method retMethod2 = TraverseBinaryExpression(bes2);
retMethod.AccessedVariables.AddRange(retMethod2.AccessedVariables);
retMethod.InvokedMethods.AddRange(retMethod2.InvokedMethods);
}
var invokedMethods = from aInvokedMethod in bes.ChildNodes().OfType<InvocationExpressionSyntax>() select aInvokedMethod;
foreach (InvocationExpressionSyntax ies in invokedMethods)
{
Method tempMethod = TraverseInvocationExpression(ies);
retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods);
retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables);
}
var castExprs = from aCastExpr in bes.ChildNodes().OfType<CastExpressionSyntax>() select aCastExpr;
foreach (CastExpressionSyntax ces in castExprs)
{
Method retMethod3 = TraverseCastExpressions(ces);
retMethod.AccessedVariables.AddRange(retMethod3.AccessedVariables);
retMethod.InvokedMethods.AddRange(retMethod3.InvokedMethods);
}
}
return retMethod;
}