本文整理汇总了C#中Attribute.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# Attribute.AddChild方法的具体用法?C# Attribute.AddChild怎么用?C# Attribute.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attribute
的用法示例。
在下文中一共展示了Attribute.AddChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAttributes
IEnumerable<Attribute> GetAttributes(IEnumerable<Mono.CSharp.Attribute> optAttributes)
{
if (optAttributes == null)
yield break;
foreach (var attr in optAttributes) {
var result = new Attribute();
result.Type = ConvertToType(attr.TypeNameExpression);
var loc = LocationsBag.GetLocations(attr);
result.HasArgumentList = loc != null;
int pos = 0;
if (loc != null)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.LPar), Roles.LPar);
if (attr.PositionalArguments != null) {
foreach (var arg in attr.PositionalArguments) {
if (arg == null)
continue;
var na = arg as NamedArgument;
if (na != null) {
var newArg = new NamedArgumentExpression();
newArg.AddChild(Identifier.Create(na.Name, Convert(na.Location)), Roles.Identifier);
var argLoc = LocationsBag.GetLocations(na);
if (argLoc != null)
newArg.AddChild(new CSharpTokenNode(Convert(argLoc [0]), Roles.Colon), Roles.Colon);
if (na.Expr != null)
newArg.AddChild((Expression)na.Expr.Accept(this), Roles.Expression);
result.AddChild(newArg, Roles.Argument);
} else {
if (arg.Expr != null)
result.AddChild((Expression)arg.Expr.Accept(this), Roles.Argument);
}
if (loc != null && pos + 1 < loc.Count)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Comma), Roles.Comma);
}
}
if (attr.NamedArguments != null) {
foreach (var arg in attr.NamedArguments) {
var na = (NamedArgument)arg;
var newArg = new NamedExpression();
newArg.AddChild(Identifier.Create(na.Name, Convert(na.Location)), Roles.Identifier);
var argLoc = LocationsBag.GetLocations(na);
if (argLoc != null)
newArg.AddChild(new CSharpTokenNode(Convert(argLoc [0]), Roles.Assign), Roles.Assign);
if (na.Expr != null)
newArg.AddChild((Expression)na.Expr.Accept(this), Roles.Expression);
result.AddChild(newArg, Roles.Argument);
if (loc != null && pos + 1 < loc.Count)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.Comma), Roles.Comma);
}
}
if (loc != null && pos < loc.Count)
result.AddChild(new CSharpTokenNode(Convert(loc [pos++]), Roles.RPar), Roles.RPar);
yield return result;
}
}
示例2: GetAttributes
IEnumerable<Attribute> GetAttributes (Attributes optAttributes)
{
if (optAttributes == null || optAttributes.Attrs == null)
yield break;
foreach (var attr in optAttributes.Attrs) {
Attribute result = new Attribute ();
result.Type = ConvertToType (attr.TypeNameExpression);
if (attr.PosArguments != null) {
foreach (var arg in attr.PosArguments) {
result.AddChild ((Expression)arg.Expr.Accept (this), Attribute.Roles.Argument);
}
}
if (attr.NamedArguments != null) {
foreach (NamedArgument na in attr.NamedArguments) {
NamedArgumentExpression newArg = new NamedArgumentExpression ();
newArg.AddChild (new Identifier (na.Name, Convert (na.Location)), NamedArgumentExpression.Roles.Identifier);
var loc = LocationsBag.GetLocations (na);
if (loc != null)
newArg.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), NamedArgumentExpression.Roles.Assign);
newArg.AddChild ((Expression)na.Expr.Accept (this), NamedArgumentExpression.Roles.Expression);
result.AddChild (newArg, Attribute.Roles.Argument);
}
}
yield return result;
}
}
示例3: GetAttributes
IEnumerable<Attribute> GetAttributes (List<Mono.CSharp.Attribute> optAttributes)
{
if (optAttributes == null)
yield break;
foreach (var attr in optAttributes) {
Attribute result = new Attribute ();
result.Type = ConvertToType (attr.TypeNameExpression);
var loc = LocationsBag.GetLocations (attr);
result.HasArgumentList = loc != null;
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), AttributeSection.Roles.LPar);
if (attr.PosArguments != null) {
foreach (var arg in attr.PosArguments) {
result.AddChild ((Expression)arg.Expr.Accept (this), Attribute.Roles.Argument);
}
}
if (attr.NamedArguments != null) {
foreach (NamedArgument na in attr.NamedArguments) {
var newArg = new NamedExpression ();
newArg.AddChild (Identifier.Create (na.Name, Convert (na.Location)), NamedExpression.Roles.Identifier);
var argLoc = LocationsBag.GetLocations (na);
if (argLoc != null)
newArg.AddChild (new CSharpTokenNode (Convert (argLoc[0]), 1), NamedExpression.Roles.Assign);
newArg.AddChild ((Expression)na.Expr.Accept (this), NamedExpression.Roles.Expression);
result.AddChild (newArg, Attribute.Roles.Argument);
}
}
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [1]), 1), AttributeSection.Roles.RPar);
yield return result;
}
}
示例4: GetAttributes
IEnumerable<Attribute> GetAttributes (List<Mono.CSharp.Attribute> optAttributes)
{
if (optAttributes == null)
yield break;
foreach (var attr in optAttributes) {
Attribute result = new Attribute ();
result.Type = ConvertToType (attr.TypeNameExpression);
if (attr.PosArguments != null) {
foreach (var arg in attr.PosArguments) {
result.AddChild ((Expression)arg.Expr.Accept (this), Attribute.Roles.Argument);
}
}
if (attr.NamedArguments != null) {
foreach (NamedArgument na in attr.NamedArguments) {
var newArg = new AssignmentExpression ();
newArg.Operator = AssignmentOperatorType.Assign;
newArg.AddChild (new IdentifierExpression (na.Name, Convert (na.Location)), AssignmentExpression.LeftRole);
var loc = LocationsBag.GetLocations (na);
if (loc != null)
newArg.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), AssignmentExpression.Roles.Assign);
newArg.AddChild ((Expression)na.Expr.Accept (this), AssignmentExpression.RightRole);
result.AddChild (newArg, Attribute.Roles.Argument);
}
}
yield return result;
}
}