本文整理汇总了C#中ArrayCreateExpression.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayCreateExpression.AddChild方法的具体用法?C# ArrayCreateExpression.AddChild怎么用?C# ArrayCreateExpression.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayCreateExpression
的用法示例。
在下文中一共展示了ArrayCreateExpression.AddChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override object Visit (ArrayCreation arrayCreationExpression)
{
var result = new ArrayCreateExpression ();
var location = LocationsBag.GetLocations (arrayCreationExpression);
if (arrayCreationExpression.NewType != null)
result.AddChild (ConvertToType (arrayCreationExpression.NewType), ArrayCreateExpression.Roles.Type);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ArrayCreateExpression.Roles.LBracket);
if (arrayCreationExpression.Arguments != null) {
var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Arguments);
for (int i = 0 ;i < arrayCreationExpression.Arguments.Count; i++) {
result.AddChild ((Expression)arrayCreationExpression.Arguments[i].Accept (this), ArrayCreateExpression.Roles.Argument);
if (commaLocations != null && i > 0)
result.AddChild (new CSharpTokenNode (Convert (commaLocations [commaLocations.Count - i]), 1), ArrayCreateExpression.Roles.Comma);
}
}
var next = arrayCreationExpression.Rank.Next;
while (next != null) {
ArraySpecifier spec = new ArraySpecifier (next.Dimension);
var loc = LocationsBag.GetLocations (next);
spec.AddChild (new CSharpTokenNode (Convert (next.Location), 1), ArraySpecifier.Roles.LBracket);
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), ArraySpecifier.Roles.RBracket);
result.AddChild (spec, ArrayCreateExpression.AdditionalArraySpecifierRole);
next = next.Next;
}
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ArrayCreateExpression.Roles.RBracket);
if (arrayCreationExpression.Initializers != null && arrayCreationExpression.Initializers.Count != 0) {
var initLocation = LocationsBag.GetLocations (arrayCreationExpression.Initializers);
ArrayInitializerExpression initializer = new ArrayInitializerExpression();
initializer.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Initializers.Location), 1), ArrayCreateExpression.Roles.LBrace);
var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Initializers.Elements);
for (int i = 0; i < arrayCreationExpression.Initializers.Count; i++) {
initializer.AddChild ((Expression)arrayCreationExpression.Initializers[i].Accept (this), ArrayInitializerExpression.Roles.Expression);
if (commaLocations != null && i > 0) {
initializer.AddChild (new CSharpTokenNode (Convert (commaLocations [commaLocations.Count - i]), 1), IndexerExpression.Roles.Comma);
}
}
if (initLocation != null)
initializer.AddChild (new CSharpTokenNode (Convert (initLocation[initLocation.Count - 1]), 1), ArrayCreateExpression.Roles.RBrace);
result.AddChild (initializer, ArrayCreateExpression.InitializerRole);
}
return result;
}
示例2: Visit
public override object Visit(ArrayCreation arrayCreationExpression)
{
var result = new ArrayCreateExpression();
var location = LocationsBag.GetLocations(arrayCreationExpression);
result.AddChild(new CSharpTokenNode(Convert(arrayCreationExpression.Location), ArrayCreateExpression.NewKeywordRole), ArrayCreateExpression.NewKeywordRole);
if (arrayCreationExpression.TypeExpression != null)
result.AddChild(ConvertToType(arrayCreationExpression.TypeExpression), Roles.Type);
var next = arrayCreationExpression.Rank;
if (arrayCreationExpression.Arguments != null) {
// skip first array rank.
next = next.Next;
if (location != null)
result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LBracket), Roles.LBracket);
var commaLocations = LocationsBag.GetLocations(arrayCreationExpression.Arguments);
for (int i = 0; i < arrayCreationExpression.Arguments.Count; i++) {
var arg = arrayCreationExpression.Arguments [i];
if (arg != null)
result.AddChild((Expression)arg.Accept(this), Roles.Argument);
if (commaLocations != null && i < commaLocations.Count)
result.AddChild(new CSharpTokenNode(Convert(commaLocations [i]), Roles.Comma), Roles.Comma);
}
if (location != null && location.Count > 1)
result.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RBracket), Roles.RBracket);
}
while (next != null) {
var spec = new ArraySpecifier(next.Dimension);
var loc = LocationsBag.GetLocations(next);
spec.AddChild(new CSharpTokenNode(Convert(next.Location), Roles.LBracket), Roles.LBracket);
result.AddChild(spec, ArrayCreateExpression.AdditionalArraySpecifierRole);
if (loc != null)
result.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.RBracket), Roles.RBracket);
next = next.Next;
}
if (arrayCreationExpression.Initializers != null) {
var initLocation = LocationsBag.GetLocations(arrayCreationExpression.Initializers);
var initializer = new ArrayInitializerExpression();
initializer.AddChild(new CSharpTokenNode(Convert(arrayCreationExpression.Initializers.Location), Roles.LBrace), Roles.LBrace);
var commaLocations = LocationsBag.GetLocations(arrayCreationExpression.Initializers.Elements);
for (int i = 0; i < arrayCreationExpression.Initializers.Count; i++) {
var init = arrayCreationExpression.Initializers [i];
if (init == null)
continue;
initializer.AddChild((Expression)init.Accept(this), Roles.Expression);
if (commaLocations != null && i < commaLocations.Count) {
initializer.AddChild(new CSharpTokenNode(Convert(commaLocations [i]), Roles.Comma), Roles.Comma);
}
}
if (initLocation != null) {
if (initLocation.Count == 2) // optional comma
initializer.AddChild(new CSharpTokenNode(Convert(initLocation [0]), Roles.Comma), Roles.Comma);
initializer.AddChild(new CSharpTokenNode(Convert(initLocation [initLocation.Count - 1]), Roles.RBrace), Roles.RBrace);
}
result.AddChild(initializer, ArrayCreateExpression.InitializerRole);
}
return result;
}
示例3: Visit
public override object Visit (ArrayCreation arrayCreationExpression)
{
var result = new ArrayCreateExpression ();
var location = LocationsBag.GetLocations (arrayCreationExpression);
result.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Location), "new".Length), ArrayCreateExpression.Roles.Keyword);
if (arrayCreationExpression.NewType != null)
result.AddChild ((AstNode)arrayCreationExpression.NewType.Accept (this), ArrayCreateExpression.Roles.ReturnType);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ArrayCreateExpression.Roles.LBracket);
if (arrayCreationExpression.Arguments != null) {
var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Arguments);
for (int i = 0 ;i < arrayCreationExpression.Arguments.Count; i++) {
result.AddChild ((AstNode)arrayCreationExpression.Arguments[i].Accept (this), ObjectCreateExpression.Roles.Initializer);
if (commaLocations != null && i > 0)
result.AddChild (new CSharpTokenNode (Convert (commaLocations [commaLocations.Count - i]), 1), IndexerExpression.Roles.Comma);
}
}
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ArrayCreateExpression.Roles.RBracket);
if (arrayCreationExpression.Initializers != null && arrayCreationExpression.Initializers.Count != 0) {
var initLocation = LocationsBag.GetLocations (arrayCreationExpression.Initializers);
result.AddChild (new CSharpTokenNode (Convert (arrayCreationExpression.Initializers.Location), 1), ArrayCreateExpression.Roles.LBrace);
var commaLocations = LocationsBag.GetLocations (arrayCreationExpression.Initializers.Elements);
for (int i = 0; i < arrayCreationExpression.Initializers.Count; i++) {
result.AddChild ((AstNode)arrayCreationExpression.Initializers[i].Accept (this), ObjectCreateExpression.Roles.Initializer);
if (commaLocations != null && i > 0) {
result.AddChild (new CSharpTokenNode (Convert (commaLocations [commaLocations.Count - i]), 1), IndexerExpression.Roles.Comma);
}
}
if (initLocation != null)
result.AddChild (new CSharpTokenNode (Convert (initLocation[initLocation.Count - 1]), 1), ArrayCreateExpression.Roles.RBrace);
}
return result;
}