本文整理汇总了C#中ConstructorDeclaration.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructorDeclaration.AddChild方法的具体用法?C# ConstructorDeclaration.AddChild怎么用?C# ConstructorDeclaration.AddChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstructorDeclaration
的用法示例。
在下文中一共展示了ConstructorDeclaration.AddChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override void Visit (Constructor c)
{
ConstructorDeclaration newConstructor = new ConstructorDeclaration ();
var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newConstructor, location);
newConstructor.AddChild (new Identifier (c.MemberName.Name, Convert (c.MemberName.Location)), AbstractNode.Roles.Identifier);
if (location != null) {
newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
}
if (c.Block != null)
newConstructor.AddChild ((INode)c.Block.Accept (this), ConstructorDeclaration.Roles.Body);
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.Roles.Member);
}
示例2: Visit
public override void Visit (Constructor c)
{
ConstructorDeclaration newConstructor = new ConstructorDeclaration ();
AddAttributeSection (newConstructor, c);
var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newConstructor, location);
newConstructor.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier);
if (location != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
AddParameter (newConstructor, c.ParameterInfo);
if (location != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
if (c.Initializer != null) {
var initializer = new ConstructorInitializer ();
initializer.ConstructorInitializerType = c.Initializer is ConstructorBaseInitializer ? ConstructorInitializerType.Base : ConstructorInitializerType.This;
var initializerLocation = LocationsBag.GetLocations (c.Initializer);
if (initializerLocation != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (initializerLocation[0]), 1), ConstructorDeclaration.Roles.Colon);
// this and base has the same length
initializer.AddChild (new CSharpTokenNode (Convert (c.Initializer.Location), "this".Length), ConstructorDeclaration.Roles.Keyword);
if (initializerLocation != null)
initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[1]), 1), ConstructorDeclaration.Roles.LPar);
AddArguments (initializer, LocationsBag.GetLocations (c.Initializer.Arguments), c.Initializer.Arguments);
if (initializerLocation != null)
initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[2]), 1), ConstructorDeclaration.Roles.RPar);
newConstructor.AddChild (initializer, ConstructorDeclaration.InitializerRole);
}
if (c.Block != null)
newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), ConstructorDeclaration.Roles.Body);
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole);
}
示例3: Visit
public override void Visit(Constructor c)
{
var newConstructor = new ConstructorDeclaration();
AddAttributeSection(newConstructor, c);
var location = LocationsBag.GetMemberLocation(c);
AddModifiers(newConstructor, location);
newConstructor.AddChild(Identifier.Create(c.MemberName.Name, Convert(c.MemberName.Location)), Roles.Identifier);
if (location != null && location.Count > 0)
newConstructor.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar);
AddParameter(newConstructor, c.ParameterInfo);
if (location != null && location.Count > 1)
newConstructor.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RPar), Roles.RPar);
if (c.Initializer != null) {
var initializer = new ConstructorInitializer();
initializer.ConstructorInitializerType = c.Initializer is ConstructorBaseInitializer ? ConstructorInitializerType.Base : ConstructorInitializerType.This;
var initializerLocation = LocationsBag.GetLocations(c.Initializer);
if (initializerLocation != null)
newConstructor.AddChild(new CSharpTokenNode(Convert(initializerLocation [0]), Roles.Colon), Roles.Colon);
if (initializerLocation != null && initializerLocation.Count > 1) {
// this and base has the same length
var r = initializer.ConstructorInitializerType == ConstructorInitializerType.This ? ConstructorInitializer.ThisKeywordRole : ConstructorInitializer.BaseKeywordRole;
initializer.AddChild(new CSharpTokenNode(Convert(c.Initializer.Location), r), r);
initializer.AddChild(new CSharpTokenNode(Convert(initializerLocation [1]), Roles.LPar), Roles.LPar);
AddArguments(initializer, c.Initializer.Arguments);
initializer.AddChild(new CSharpTokenNode(Convert(initializerLocation [2]), Roles.RPar), Roles.RPar);
newConstructor.AddChild(initializer, ConstructorDeclaration.InitializerRole);
}
}
if (c.Block != null)
newConstructor.AddChild((BlockStatement)c.Block.Accept(this), Roles.Body);
typeStack.Peek().AddChild(newConstructor, Roles.TypeMemberRole);
}
示例4: Visit
public override void Visit (Constructor c)
{
ConstructorDeclaration newConstructor = new ConstructorDeclaration ();
var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newConstructor, location);
newConstructor.AddChild (new Identifier (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier);
if (location != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
AddParameter (newConstructor, c.ParameterInfo);
if (location != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
if (c.Initializer != null)
{
newConstructor.Initializer = new ConstructorInitializer();
if (c.Initializer is ConstructorBaseInitializer)
newConstructor.Initializer.ConstructorInitializerType = ConstructorInitializerType.Base;
if (c.Initializer is ConstructorThisInitializer)
newConstructor.Initializer.ConstructorInitializerType = ConstructorInitializerType.This;
AddArguments(newConstructor.Initializer, location, c.Initializer.Arguments);
}
if (c.Block != null)
newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), ConstructorDeclaration.Roles.Body);
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole);
}