本文整理汇总了C#中ParameterDeclaration.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterDeclaration.AddChild方法的具体用法?C# ParameterDeclaration.AddChild怎么用?C# ParameterDeclaration.AddChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterDeclaration
的用法示例。
在下文中一共展示了ParameterDeclaration.AddChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddParameter
void AddParameter(AstNode parent, AParametersCollection parameters)
{
if (parameters == null)
return;
var paramLocation = LocationsBag.GetLocations(parameters);
for (int i = 0; i < parameters.Count; i++) {
var p = (Parameter)parameters.FixedParameters [i];
if (p == null)
continue;
var location = LocationsBag.GetLocations(p);
var parameterDeclarationExpression = new ParameterDeclaration();
AddAttributeSection(parameterDeclarationExpression, p);
switch (p.ModFlags) {
case Parameter.Modifier.OUT:
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Out;
if (location != null)
parameterDeclarationExpression.AddChild(new CSharpTokenNode(Convert(location [0]), ParameterDeclaration.OutModifierRole), ParameterDeclaration.OutModifierRole);
break;
case Parameter.Modifier.REF:
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Ref;
if (location != null)
parameterDeclarationExpression.AddChild(new CSharpTokenNode(Convert(location [0]), ParameterDeclaration.RefModifierRole), ParameterDeclaration.RefModifierRole);
break;
case Parameter.Modifier.PARAMS:
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Params;
if (location != null)
parameterDeclarationExpression.AddChild(new CSharpTokenNode(Convert(location [0]), ParameterDeclaration.ParamsModifierRole), ParameterDeclaration.ParamsModifierRole);
break;
default:
if (p.HasExtensionMethodModifier) {
parameterDeclarationExpression.ParameterModifier = ParameterModifier.This;
if (location != null) {
parameterDeclarationExpression.AddChild(new CSharpTokenNode(Convert(location [0]), ParameterDeclaration.ThisModifierRole), ParameterDeclaration.ThisModifierRole);
}
}
break;
}
if (p.TypeExpression != null) // lambdas may have no types (a, b) => ...
parameterDeclarationExpression.AddChild(ConvertToType(p.TypeExpression), Roles.Type);
if (p.Name != null)
parameterDeclarationExpression.AddChild(Identifier.Create(p.Name, Convert(p.Location)), Roles.Identifier);
if (p.HasDefaultValue) {
if (location != null && location.Count > 1)
parameterDeclarationExpression.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.Assign), Roles.Assign);
parameterDeclarationExpression.AddChild((Expression)p.DefaultValue.Accept(this), Roles.Expression);
}
parent.AddChild(parameterDeclarationExpression, Roles.Parameter);
if (paramLocation != null && i < paramLocation.Count) {
parent.AddChild(new CSharpTokenNode(Convert(paramLocation [i]), Roles.Comma), Roles.Comma);
}
}
}
示例2: AddParameter
void AddParameter (AstNode parent, Mono.CSharp.AParametersCollection parameters)
{
if (parameters == null)
return;
var paramLocation = LocationsBag.GetLocations (parameters);
for (int i = 0; i < parameters.Count; i++) {
if (paramLocation != null && i > 0 && i - 1 < paramLocation.Count)
parent.AddChild (new CSharpTokenNode (Convert (paramLocation[i - 1]), 1), ParameterDeclaration.Roles.Comma);
var p = (Parameter)parameters.FixedParameters[i];
var location = LocationsBag.GetLocations (p);
ParameterDeclaration parameterDeclarationExpression = new ParameterDeclaration ();
switch (p.ModFlags) {
case Parameter.Modifier.OUT:
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Out;
if (location != null)
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "out".Length), ParameterDeclaration.Roles.Keyword);
break;
case Parameter.Modifier.REF:
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Ref;
if (location != null)
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "ref".Length), ParameterDeclaration.Roles.Keyword);
break;
case Parameter.Modifier.PARAMS:
parameterDeclarationExpression.ParameterModifier = ParameterModifier.Params;
if (location != null)
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "params".Length), ParameterDeclaration.Roles.Keyword);
break;
case Parameter.Modifier.This:
parameterDeclarationExpression.ParameterModifier = ParameterModifier.This;
if (location != null)
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[0]), "this".Length), ParameterDeclaration.Roles.Keyword);
break;
}
if (p.TypeExpression != null) // lambdas may have no types (a, b) => ...
parameterDeclarationExpression.AddChild ((AstNode)p.TypeExpression.Accept (this), ParameterDeclaration.Roles.ReturnType);
parameterDeclarationExpression.AddChild (new Identifier (p.Name, Convert (p.Location)), ParameterDeclaration.Roles.Identifier);
if (p.HasDefaultValue) {
if (location != null)
parameterDeclarationExpression.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ParameterDeclaration.Roles.Assign);
parameterDeclarationExpression.AddChild ((AstNode)p.DefaultValue.Accept (this), ParameterDeclaration.Roles.Expression);
}
parent.AddChild (parameterDeclarationExpression, InvocationExpression.Roles.Parameter);
}
}