本文整理匯總了C#中System.Attribute.AddChild方法的典型用法代碼示例。如果您正苦於以下問題:C# Attribute.AddChild方法的具體用法?C# Attribute.AddChild怎麽用?C# Attribute.AddChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Attribute
的用法示例。
在下文中一共展示了Attribute.AddChild方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetAttributes
IEnumerable<Attribute> GetAttributes (IEnumerable<Mono.CSharpPs.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;
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) {
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 (NamedArgument na in attr.NamedArguments) {
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;
}
}