本文整理汇总了C#中ArrayInitializerExpression.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayInitializerExpression.AddChild方法的具体用法?C# ArrayInitializerExpression.AddChild怎么用?C# ArrayInitializerExpression.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayInitializerExpression
的用法示例。
在下文中一共展示了ArrayInitializerExpression.AddChild方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override object Visit(ArrayInitializer arrayInitializer)
{
var result = new ArrayInitializerExpression();
var location = LocationsBag.GetLocations(arrayInitializer);
result.AddChild(new CSharpTokenNode(Convert(arrayInitializer.Location), Roles.LBrace), Roles.LBrace);
var commaLocations = LocationsBag.GetLocations(arrayInitializer.Elements);
for (int i = 0; i < arrayInitializer.Count; i++) {
var init = arrayInitializer [i];
if (init == null)
continue;
result.AddChild((Expression)init.Accept(this), Roles.Expression);
if (commaLocations != null && i < commaLocations.Count)
result.AddChild(new CSharpTokenNode(Convert(commaLocations [i]), Roles.Comma), Roles.Comma);
}
if (location != null) {
if (location.Count == 2) // optional comma
result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.Comma), Roles.Comma);
result.AddChild(new CSharpTokenNode(Convert(location [location.Count - 1]), Roles.RBrace), Roles.RBrace);
}
return result;
}
示例2: AddConvertCollectionOrObjectInitializers
void AddConvertCollectionOrObjectInitializers(Expression init, CollectionOrObjectInitializers minit)
{
var initLoc = LocationsBag.GetLocations(minit);
var commaLoc = LocationsBag.GetLocations(minit.Initializers);
int curComma = 0;
init.AddChild(new CSharpTokenNode(Convert(minit.Location), Roles.LBrace), Roles.LBrace);
foreach (var expr in minit.Initializers) {
var collectionInit = expr as CollectionElementInitializer;
if (collectionInit != null) {
AstNode parent;
// For ease of use purposes in the resolver the ast representation
// of { a, b, c } is { {a}, {b}, {c} } - but the generated ArrayInitializerExpression
// can be identified by expr.IsSingleElement.
if (!collectionInit.IsSingle) {
parent = new ArrayInitializerExpression();
parent.AddChild(new CSharpTokenNode(Convert(collectionInit.Location), Roles.LBrace), Roles.LBrace);
} else {
parent = ArrayInitializerExpression.CreateSingleElementInitializer();
}
if (collectionInit.Arguments != null) {
for (int i = 0; i < collectionInit.Arguments.Count; i++) {
var arg = collectionInit.Arguments [i] as CollectionElementInitializer.ElementInitializerArgument;
if (arg == null || arg.Expr == null)
continue;
parent.AddChild(
(Expression)arg.Expr.Accept(this),
Roles.Expression
);
}
}
if (!collectionInit.IsSingle) {
var braceLocs = LocationsBag.GetLocations(expr);
if (braceLocs != null)
parent.AddChild(new CSharpTokenNode(Convert(braceLocs [0]), Roles.RBrace), Roles.RBrace);
}
init.AddChild((ArrayInitializerExpression)parent, Roles.Expression);
} else {
var eleInit = expr as ElementInitializer;
if (eleInit != null) {
var nexpr = new NamedExpression();
nexpr.AddChild(
Identifier.Create(eleInit.Name, Convert(eleInit.Location)),
Roles.Identifier
);
var assignLoc = LocationsBag.GetLocations(eleInit);
if (assignLoc != null)
nexpr.AddChild(new CSharpTokenNode(Convert(assignLoc [0]), Roles.Assign), Roles.Assign);
if (eleInit.Source != null) {
var colInit = eleInit.Source as CollectionOrObjectInitializers;
if (colInit != null) {
var arrInit = new ArrayInitializerExpression();
AddConvertCollectionOrObjectInitializers(
arrInit,
colInit
);
nexpr.AddChild(arrInit, Roles.Expression);
} else {
nexpr.AddChild((Expression)eleInit.Source.Accept(this), Roles.Expression);
}
}
init.AddChild(nexpr, Roles.Expression);
}
}
if (commaLoc != null && curComma < commaLoc.Count)
init.AddChild(new CSharpTokenNode(Convert(commaLoc [curComma++]), Roles.Comma), Roles.Comma);
}
if (initLoc != null) {
if (initLoc.Count == 2) // optional comma
init.AddChild(new CSharpTokenNode(Convert(initLoc [0]), Roles.Comma), Roles.Comma);
init.AddChild(new CSharpTokenNode(Convert(initLoc [initLoc.Count - 1]), Roles.RBrace), Roles.RBrace);
}
}
示例3: AddConvertCollectionOrObjectInitializers
void AddConvertCollectionOrObjectInitializers (Expression init, CollectionOrObjectInitializers minit)
{
var initLoc = LocationsBag.GetLocations (minit);
var commaLoc = LocationsBag.GetLocations (minit.Initializers);
int curComma = 0;
if (initLoc != null)
init.AddChild (new CSharpTokenNode (Convert (initLoc [0]), 1), ArrayInitializerExpression.Roles.LBrace);
foreach (var expr in minit.Initializers) {
var collectionInit = expr as CollectionElementInitializer;
if (collectionInit != null) {
var parent = new ArrayInitializerExpression ();
var braceLocs = LocationsBag.GetLocations (expr);
if (braceLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (braceLocs [0]), 1), ArrayInitializerExpression.Roles.LBrace);
for (int i = 0; i < collectionInit.Arguments.Count; i++) {
var arg = collectionInit.Arguments [i] as CollectionElementInitializer.ElementInitializerArgument;
if (arg == null)
continue;
parent.AddChild ((ICSharpCode.NRefactory.CSharp.Expression)arg.Expr.Accept (this), ArrayInitializerExpression.Roles.Expression);
}
if (braceLocs != null)
parent.AddChild (new CSharpTokenNode (Convert (braceLocs [1]), 1), ArrayInitializerExpression.Roles.RBrace);
init.AddChild (parent, ArrayInitializerExpression.Roles.Expression);
} else {
var eleInit = expr as ElementInitializer;
if (eleInit != null) {
var nexpr = new NamedExpression ();
nexpr.AddChild (Identifier.Create (eleInit.Name, Convert (eleInit.Location)), NamedArgumentExpression.Roles.Identifier);
var assignLoc = LocationsBag.GetLocations (eleInit);
if (assignLoc != null)
nexpr.AddChild (new CSharpTokenNode (Convert (assignLoc [0]), 1), NamedArgumentExpression.Roles.Assign);
if (eleInit.Source != null) {
if (eleInit.Source is CollectionOrObjectInitializers) {
var arrInit = new ArrayInitializerExpression ();
AddConvertCollectionOrObjectInitializers (arrInit, eleInit.Source as CollectionOrObjectInitializers);
nexpr.AddChild (arrInit, NamedArgumentExpression.Roles.Expression);
} else {
nexpr.AddChild ((Expression)eleInit.Source.Accept (this), NamedArgumentExpression.Roles.Expression);
}
}
init.AddChild (nexpr, ArrayInitializerExpression.Roles.Expression);
}
}
if (commaLoc != null && curComma < commaLoc.Count)
init.AddChild (new CSharpTokenNode (Convert (commaLoc [curComma++]), 1), ArrayInitializerExpression.Roles.Comma);
}
if (initLoc != null) {
if (initLoc.Count == 3) // optional comma
init.AddChild (new CSharpTokenNode (Convert (initLoc [1]), 1), ArrayInitializerExpression.Roles.Comma);
init.AddChild (new CSharpTokenNode (Convert (initLoc [initLoc.Count - 1]), 1), ArrayInitializerExpression.Roles.RBrace);
}
}
示例4: 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;
}
示例5: ConvertCollectionOrObjectInitializers
ArrayInitializerExpression ConvertCollectionOrObjectInitializers (CollectionOrObjectInitializers minit)
{
if (minit == null)
return null;
var init = new ArrayInitializerExpression ();
var braceLocs = LocationsBag.GetLocations (minit);
if (braceLocs != null)
init.AddChild (new CSharpTokenNode (Convert (braceLocs[0]), 1), ArrayInitializerExpression.Roles.LBrace);
AddConvertCollectionOrObjectInitializers (init, minit);
if (braceLocs != null)
init.AddChild (new CSharpTokenNode (Convert (braceLocs[1]), 1), ArrayInitializerExpression.Roles.RBrace);
return init;
}
示例6: Visit
public override object Visit (ArrayInitializer arrayInitializer)
{
var result = new ArrayInitializerExpression ();
var location = LocationsBag.GetLocations (arrayInitializer);
result.AddChild (new CSharpTokenNode (Convert (arrayInitializer.Location), "[".Length), ArrayInitializerExpression.Roles.LBracket);
var commaLocations = LocationsBag.GetLocations (arrayInitializer.Elements);
for (int i = 0; i < arrayInitializer.Count; i++) {
result.AddChild ((AstNode)arrayInitializer[i].Accept (this), ArrayInitializerExpression.Roles.Initializer);
if (commaLocations != null && i < commaLocations.Count)
result.AddChild (new CSharpTokenNode (Convert (commaLocations[i]), ",".Length), ArrayInitializerExpression.Roles.Comma);
}
if (location != null) {
if (location.Count == 2) // optional comma
result.AddChild (new CSharpTokenNode (Convert (location[1]), ",".Length), ArrayInitializerExpression.Roles.Comma);
result.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), "]".Length), ArrayInitializerExpression.Roles.RBracket);
}
return result;
}
示例7: Visit
public override object Visit (ArrayInitializer arrayInitializer)
{
var result = new ArrayInitializerExpression ();
var location = LocationsBag.GetLocations (arrayInitializer);
var commaLocations = LocationsBag.GetLocations (arrayInitializer.Elements);
for (int i = 0; i < arrayInitializer.Count; i++) {
result.AddChild((Expression)arrayInitializer[i].Accept(this), ArrayInitializerExpression.Roles.Expression);
}
return result;
}