本文整理汇总了C#中ArrayCreateExpression.GetParent方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayCreateExpression.GetParent方法的具体用法?C# ArrayCreateExpression.GetParent怎么用?C# ArrayCreateExpression.GetParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayCreateExpression
的用法示例。
在下文中一共展示了ArrayCreateExpression.GetParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitArrayCreateExpression
public override void VisitArrayCreateExpression (ArrayCreateExpression arrayCreateExpression)
{
base.VisitArrayCreateExpression (arrayCreateExpression);
if (arrayCreateExpression.Arguments.Count != 1 || !arrayCreateExpression.Initializer.IsNull)
return;
var count = arrayCreateExpression.Arguments.First ();
if (count is PrimitiveExpression && Convert.ToInt32 (((PrimitiveExpression)count).Value) == 0)
return;
var s = arrayCreateExpression.GetParent<Statement> ();
if (s == null)
return;
var find = new FindFirstUseOfArray ();
var variableDeclarationStatement = s as VariableDeclarationStatement;
if (variableDeclarationStatement != null) {
var v = arrayCreateExpression.GetParent <VariableInitializer> ();
find.Variable = new IdentifierExpression (v.Name);
} else {
var es = s as ExpressionStatement;
if (es != null && es.Expression is AssignmentExpression) {
find.Variable = ((AssignmentExpression)es.Expression).Left;
} else {
return; // Don't know what's going on
}
}
if (find.Variable == null)
return;
arrayCreateExpression.GetParent<EntityDeclaration> ().AcceptVisitor (find);
if ((find.First is AssignmentExpression))
return;
var i = new IdentifierExpression ("_ai");
var def = GetDefaultValue (arrayCreateExpression.Type);
var init = new ForStatement {
Condition = new BinaryOperatorExpression (
i,
BinaryOperatorType.LessThan,
new MemberReferenceExpression ((Expression)find.Variable.Clone (), "length")),
EmbeddedStatement = new ExpressionStatement (
new AssignmentExpression (
new IndexerExpression ((Expression)find.Variable.Clone (), i.Clone ()),
def.Clone ())),
};
init.Initializers.Add (new VariableDeclarationStatement (new PrimitiveType ("number"), i.Identifier, new PrimitiveExpression (0)));
init.Iterators.Add (new ExpressionStatement (new UnaryOperatorExpression (UnaryOperatorType.Increment, (Expression)i.Clone ())));
s.Parent.InsertChildAfter (s, init, (Role<Statement>)s.Role);
}