本文整理汇总了C#中VariableInitializer.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# VariableInitializer.AddChild方法的具体用法?C# VariableInitializer.AddChild怎么用?C# VariableInitializer.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VariableInitializer
的用法示例。
在下文中一共展示了VariableInitializer.AddChild方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override void Visit(Const c)
{
var location = LocationsBag.GetMemberLocation(c);
var newField = new FieldDeclaration();
AddAttributeSection(newField, c);
AddModifiers(newField, location);
if (location != null)
newField.AddChild(new CSharpModifierToken(Convert(location [0]), Modifiers.Const), EntityDeclaration.ModifierRole);
newField.AddChild(ConvertToType(c.TypeExpression), Roles.Type);
var variable = new VariableInitializer();
variable.AddChild(Identifier.Create(c.MemberName.Name, Convert(c.MemberName.Location)), Roles.Identifier);
if (c.Initializer != null) {
variable.AddChild(new CSharpTokenNode(Convert(c.Initializer.Location), Roles.Assign), Roles.Assign);
variable.AddChild((Expression)c.Initializer.Accept(this), Roles.Expression);
}
newField.AddChild(variable, Roles.Variable);
if (c.Declarators != null) {
foreach (var decl in c.Declarators) {
var declLoc = LocationsBag.GetLocations(decl);
if (declLoc != null)
newField.AddChild(new CSharpTokenNode(Convert(declLoc [0]), Roles.Comma), Roles.Comma);
variable = new VariableInitializer();
variable.AddChild(Identifier.Create(decl.Name.Value, Convert(decl.Name.Location)), Roles.Identifier);
if (decl.Initializer != null) {
variable.AddChild(new CSharpTokenNode(Convert(decl.Initializer.Location), Roles.Assign), Roles.Assign);
variable.AddChild((Expression)decl.Initializer.Accept(this), Roles.Expression);
}
newField.AddChild(variable, Roles.Variable);
}
}
if (location != null)
newField.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.Semicolon), Roles.Semicolon);
typeStack.Peek().AddChild(newField, Roles.TypeMemberRole);
}
示例2: CreateVariableDeclaration
VariableDeclarationStatement CreateVariableDeclaration (LocalInfo info)
{
VariableDeclarationStatement result = new VariableDeclarationStatement ();
result.AddChild ((INode)info.Type.Accept (this), CatchClause.Roles.ReturnType);
VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (info.Name, Convert (info.Location)), AbstractNode.Roles.Identifier);
result.AddChild (variable, AbstractNode.Roles.Initializer);
result.AddChild (new Identifier (info.Name, Convert (info.Location)), CatchClause.Roles.ReturnType);
return result;
}
示例3: CreateUsingStatement
public UsingStatement CreateUsingStatement(Block blockStatement)
{
var usingResult = new UsingStatement();
Mono.CSharp.Statement cur = blockStatement.Statements [0];
var u = cur as Using;
if (u != null) {
usingResult.AddChild(new CSharpTokenNode(Convert(u.loc), UsingStatement.UsingKeywordRole), UsingStatement.UsingKeywordRole);
usingResult.AddChild(new CSharpTokenNode(Convert(blockStatement.StartLocation), Roles.LPar), Roles.LPar);
if (u.Variables != null) {
var initializer = new VariableInitializer {
NameToken = Identifier.Create(u.Variables.Variable.Name, Convert(u.Variables.Variable.Location)),
};
var loc = LocationsBag.GetLocations(u.Variables);
if (loc != null)
initializer.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.Assign), Roles.Assign);
if (u.Variables.Initializer != null)
initializer.Initializer = u.Variables.Initializer.Accept(this) as Expression;
var varDec = new VariableDeclarationStatement {
Type = ConvertToType(u.Variables.TypeExpression),
Variables = { initializer }
};
if (u.Variables.Declarators != null) {
foreach (var decl in u.Variables.Declarators) {
var declLoc = LocationsBag.GetLocations(decl);
var init = new VariableInitializer();
if (declLoc != null && declLoc.Count > 0)
varDec.AddChild(new CSharpTokenNode(Convert(declLoc [0]), Roles.Comma), Roles.Comma);
init.AddChild(Identifier.Create(decl.Variable.Name, Convert(decl.Variable.Location)), Roles.Identifier);
if (decl.Initializer != null) {
if (declLoc != null && declLoc.Count > 1)
init.AddChild(new CSharpTokenNode(Convert(declLoc [1]), Roles.Assign), Roles.Assign);
init.AddChild((Expression)decl.Initializer.Accept(this), Roles.Expression);
}
varDec.AddChild(init, Roles.Variable);
}
}
usingResult.AddChild(varDec, UsingStatement.ResourceAcquisitionRole);
}
cur = u.Statement;
usingResult.AddChild(new CSharpTokenNode(Convert(blockStatement.EndLocation), Roles.RPar), Roles.RPar);
if (cur != null)
usingResult.AddChild((Statement)cur.Accept(this), Roles.EmbeddedStatement);
}
return usingResult;
}
示例4: Visit
public override void Visit (Field f)
{
var location = LocationsBag.GetMemberLocation (f);
FieldDeclaration newField = new FieldDeclaration ();
AddModifiers (newField, location);
newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type);
VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier);
if (f.Initializer != null) {
if (location != null)
variable.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FieldDeclaration.Roles.Assign);
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)f.Initializer.Accept (this), VariableInitializer.Roles.Expression);
}
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
if (f.Declarators != null) {
foreach (var decl in f.Declarators) {
var declLoc = LocationsBag.GetLocations (decl);
if (declLoc != null)
newField.AddChild (new CSharpTokenNode (Convert (declLoc[0]), 1), FieldDeclaration.Roles.Comma);
variable = new VariableInitializer ();
variable.AddChild (new Identifier (decl.Name.Value, Convert (decl.Name.Location)), VariableInitializer.Roles.Identifier);
if (decl.Initializer != null) {
variable.AddChild (new CSharpTokenNode (Convert (decl.Initializer.Location), 1), FieldDeclaration.Roles.Assign);
variable.AddChild ((MonoDevelop.CSharp.Ast.Expression)decl.Initializer.Accept (this), VariableInitializer.Roles.Expression);
}
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
}
}
if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), 1), FieldDeclaration.Roles.Semicolon);
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole);
}
示例5: Visit
public override void Visit (EventField e)
{
EventDeclaration newEvent = new EventDeclaration ();
AddAttributeSection (newEvent, e);
var location = LocationsBag.GetMemberLocation (e);
AddModifiers (newEvent, location);
if (location != null)
newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), EventDeclaration.Roles.Keyword);
newEvent.AddChild (ConvertToType (e.TypeName), AstNode.Roles.Type);
VariableInitializer variable = new VariableInitializer ();
variable.AddChild (Identifier.Create (e.MemberName.Name, Convert (e.MemberName.Location)), FieldDeclaration.Roles.Identifier);
if (e.Initializer != null) {
if (location != null)
variable.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FieldDeclaration.Roles.Assign);
variable.AddChild ((Expression)e.Initializer.Accept (this), VariableInitializer.Roles.Expression);
}
newEvent.AddChild (variable, FieldDeclaration.Roles.Variable);
if (e.Declarators != null) {
foreach (var decl in e.Declarators) {
var declLoc = LocationsBag.GetLocations (decl);
if (declLoc != null)
newEvent.AddChild (new CSharpTokenNode (Convert (declLoc [0]), 1), FieldDeclaration.Roles.Comma);
variable = new VariableInitializer ();
variable.AddChild (Identifier.Create (decl.Name.Value, Convert (decl.Name.Location)), VariableInitializer.Roles.Identifier);
if (decl.Initializer != null) {
if (declLoc != null)
variable.AddChild (new CSharpTokenNode (Convert (declLoc [1]), 1), FieldDeclaration.Roles.Assign);
variable.AddChild ((Expression)decl.Initializer.Accept (this), VariableInitializer.Roles.Expression);
}
newEvent.AddChild (variable, FieldDeclaration.Roles.Variable);
}
}
if (location != null)
newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), ";".Length), EventDeclaration.Roles.Semicolon);
typeStack.Peek ().AddChild (newEvent, TypeDeclaration.MemberRole);
}
示例6: CreateUsingStatement
public UsingStatement CreateUsingStatement (Block blockStatement)
{
var usingResult = new UsingStatement ();
Mono.CSharp.Statement cur = blockStatement.Statements[0];
if (cur is Using) {
Using u = (Using)cur;
usingResult.AddChild (new CSharpTokenNode (Convert (u.loc), "using".Length), UsingStatement.Roles.Keyword);
usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), UsingStatement.Roles.LPar);
if (u.Variables != null) {
var initializer = new VariableInitializer () {
NameToken = Identifier.Create (u.Variables.Variable.Name, Convert (u.Variables.Variable.Location)),
};
var loc = LocationsBag.GetLocations (u.Variables);
if (loc != null)
initializer.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), VariableInitializer.Roles.Assign);
if (u.Variables.Initializer != null)
initializer.Initializer = u.Variables.Initializer.Accept (this) as Expression;
var varDec = new VariableDeclarationStatement () {
Type = ConvertToType (u.Variables.TypeExpression),
Variables = { initializer }
};
usingResult.AddChild (varDec, UsingStatement.ResourceAcquisitionRole);
}
cur = u.Statement;
usingResult.AddChild (new CSharpTokenNode (Convert (blockStatement.EndLocation), 1), UsingStatement.Roles.RPar);
if (cur != null)
usingResult.AddChild ((Statement)cur.Accept (this), UsingStatement.Roles.EmbeddedStatement);
}
return usingResult;
}
示例7: AddFixedFieldInitializer
void AddFixedFieldInitializer (VariableInitializer variable, Expression initializer)
{
if (initializer == null)
return;
if (initializer is ConstInitializer) {
variable.AddChild (new CSharpTokenNode (Convert (initializer.Location), 1), FieldDeclaration.Roles.LBracket);
variable.AddChild ((INode)initializer.Accept (this), FieldDeclaration.Roles.Initializer);
var initializerLoc = LocationsBag.GetLocations (initializer);
if (initializerLoc != null)
variable.AddChild (new CSharpTokenNode (Convert (initializerLoc[0]), 1), FieldDeclaration.Roles.RBracket);
} else {
variable.AddChild (new CSharpTokenNode (Convert (initializer.Location), 1), FieldDeclaration.Roles.Assign);
variable.AddChild ((INode)initializer.Accept (this), FieldDeclaration.Roles.Initializer);
}
}
示例8: Visit
public override object Visit (BlockConstantDeclaration blockVariableDeclaration)
{
var result = new VariableDeclarationStatement ();
result.AddChild ((AstNode)blockVariableDeclaration.TypeExpression.Accept (this), VariableDeclarationStatement.Roles.ReturnType);
var varInit = new VariableInitializer ();
var location = LocationsBag.GetLocations (blockVariableDeclaration);
if (location != null)
varInit.AddChild (new CSharpTokenNode (Convert (location[0]), "const".Length), VariableInitializer.Roles.Modifier);
varInit.AddChild (new Identifier (blockVariableDeclaration.Variable.Name, Convert (blockVariableDeclaration.Variable.Location)), VariableInitializer.Roles.Identifier);
if (blockVariableDeclaration.Initializer != null) {
if (location != null)
varInit.AddChild (new CSharpTokenNode (Convert (location[1]), 1), VariableInitializer.Roles.Assign);
varInit.AddChild ((AstNode)blockVariableDeclaration.Initializer.Accept (this), VariableInitializer.Roles.Initializer);
}
result.AddChild (varInit, VariableDeclarationStatement.Roles.Initializer);
if (blockVariableDeclaration.Declarators != null) {
foreach (var decl in blockVariableDeclaration.Declarators) {
var loc = LocationsBag.GetLocations (decl);
var init = new VariableInitializer ();
init.AddChild (new Identifier (decl.Variable.Name, Convert (decl.Variable.Location)), VariableInitializer.Roles.Identifier);
if (decl.Initializer != null) {
if (loc != null)
init.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), VariableInitializer.Roles.Assign);
init.AddChild ((AstNode)decl.Initializer.Accept (this), VariableInitializer.Roles.Initializer);
if (loc != null && loc.Count > 1)
result.AddChild (new CSharpTokenNode (Convert (loc[1]), 1), VariableInitializer.Roles.Comma);
} else {
if (loc != null && loc.Count > 0)
result.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), VariableInitializer.Roles.Comma);
}
result.AddChild (init, VariableDeclarationStatement.Roles.Initializer);
}
}
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), 1), VariableDeclarationStatement.Roles.Semicolon);
return result;
}
示例9: Visit
public override void Visit (EnumMember em)
{
EnumMemberDeclaration newField = new EnumMemberDeclaration ();
VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (em.Name, Convert (em.Location)), DomNode.Roles.Identifier);
if (em.Initializer != null) {
var initializer = (DomNode)em.Initializer.Accept (this);
if (initializer != null)
variable.AddChild (initializer, DomNode.Roles.Initializer);
}
newField.AddChild (variable, DomNode.Roles.Initializer);
typeStack.Peek ().AddChild (newField, TypeDeclaration.Roles.Member);
}
示例10: Visit
public override void Visit (EnumMember em)
{
FieldDeclaration newField = new FieldDeclaration ();
VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (em.Name, Convert (em.Location)), AbstractNode.Roles.Identifier);
if (em.Initializer != null) {
INode initializer = (INode)Visit (em.Initializer);
if (initializer != null)
variable.AddChild (initializer, AbstractNode.Roles.Initializer);
}
newField.AddChild (variable, AbstractNode.Roles.Initializer);
typeStack.Peek ().AddChild (newField, TypeDeclaration.Roles.Member);
}