本文整理汇总了C#中VariableInitializer.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# VariableInitializer.Remove方法的具体用法?C# VariableInitializer.Remove怎么用?C# VariableInitializer.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VariableInitializer
的用法示例。
在下文中一共展示了VariableInitializer.Remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitVariableInitializer
//.........这里部分代码省略.........
}
}
}
if (!varInit.IsNull && varRefs.Length == 1)
{
AstNode varRef = varRefs[0];
var refParent = varRef.Parent;
// 排除 ref xxx、out xxx
var dirExp = refParent as DirectionExpression;
if (dirExp == null || dirExp.FieldDirection == FieldDirection.None)
{
// 排除 xxx++、xxx--、xxx += ……、……
var unary = refParent as UnaryOperatorExpression;
if (unary != null)
{
if (unary.Operator == UnaryOperatorType.Not ||
unary.Operator == UnaryOperatorType.BitNot ||
unary.Operator == UnaryOperatorType.Minus ||
unary.Operator == UnaryOperatorType.Plus ||
unary.Operator == UnaryOperatorType.Increment ||
unary.Operator == UnaryOperatorType.Decrement ||
unary.Operator == UnaryOperatorType.PostIncrement ||
unary.Operator == UnaryOperatorType.PostDecrement ||
unary.Operator == UnaryOperatorType.Dereference ||
unary.Operator == UnaryOperatorType.AddressOf)
{
varRef = null;
}
}
if (varRef != null)
{
// 如果在 varInit 与 varRef 之间包含变量或成员引用,放弃替换
var hasReference = false;
var beginCompare = false;
foreach (var x in block.Descendants)
{
if (x == varRef) break;
if (beginCompare)
{
if (x is MemberReferenceExpression) { hasReference = true; break; }
if (x is IdentifierExpression) { hasReference = true; break; }
}
else if (x == varInit)
{
beginCompare = true;
}
}
if (!hasReference)
{
// 确定是否需要将初始化表达式括起来
var binInit = varInit as BinaryOperatorExpression;
var binRef = refParent as BinaryOperatorExpression;
if (binInit != null && binRef != null)
{
//BitwiseAnd x & y
//BitwiseOr x | y
//ConditionalAnd x && y
//ConditionalOr x || y
//ExclusiveOr x ^ y
//GreaterThan x > y
//GreaterThanOrEqual x >= y
//Equality x == y
//InEquality x != y
//LessThan x < y
//LessThanOrEqual x <= y
//Add x + y
//Subtract x - y
//Multiply x * y
//Divide x / y
//Modulus x % y
//ShiftLeft x << y
//ShiftRight x >> y
//NullCoalescing x ?? y
// (T)x
// x is T
// x as T
varInit = new ParenthesizedExpression(varInit.Detach());
}
varInit.Remove();
varRef.ReplaceWith(varInit);
var decl = e.Parent as VariableDeclarationStatement;
if (decl != null && decl.Variables.Count == 1)
{
decl.Remove();
}
else
{
e.Remove();
}
if (ifElse != null) ifElse.Remove();
}
}
}
}
}
}
}