本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax类的典型用法代码示例。如果您正苦于以下问题:C# ParameterSyntax类的具体用法?C# ParameterSyntax怎么用?C# ParameterSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParameterSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了ParameterSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntroduceFieldFromConstructor
public static SyntaxNode IntroduceFieldFromConstructor(SyntaxNode root, ConstructorDeclarationSyntax constructorStatement, ParameterSyntax parameter)
{
var oldClass = constructorStatement.FirstAncestorOrSelf<ClassDeclarationSyntax>();
var newClass = oldClass;
var fieldName = parameter.Identifier.ValueText;
var fieldType = parameter.Type;
var members = ExtractMembersFromClass(oldClass.Members);
var addMember = false;
if (!members.Any(p => p.Key == fieldName && p.Value == fieldType.ToString()))
{
var identifierPostFix = 0;
while (members.Any(p => p.Key == fieldName))
fieldName = parameter.Identifier.ValueText + ++identifierPostFix;
addMember = true;
}
var assignmentField = SyntaxFactory.ExpressionStatement(SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(),
SyntaxFactory.IdentifierName(fieldName)), SyntaxFactory.IdentifierName(parameter.Identifier.ValueText)));
var newConstructor = constructorStatement.WithBody(constructorStatement.Body.AddStatements(assignmentField));
newClass = newClass.ReplaceNode(constructorStatement, newConstructor);
if (addMember)
{
var newField = SyntaxFactory.FieldDeclaration(SyntaxFactory.VariableDeclaration(parameter.Type)
.WithVariables(SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(SyntaxFactory.Identifier(fieldName)))))
.WithModifiers(SyntaxFactory.TokenList(new[] { SyntaxFactory.Token(SyntaxKind.PrivateKeyword), SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword) }))
.WithAdditionalAnnotations(Formatter.Annotation);
newClass = newClass.WithMembers(newClass.Members.Insert(0, newField)).WithoutAnnotations(Formatter.Annotation);
}
var newRoot = root.ReplaceNode(oldClass, newClass);
return newRoot;
}
示例2: GetActions
protected IEnumerable<CodeAction> GetActions(Document document, SemanticModel semanticModel, SyntaxNode root, TextSpan span, ParameterSyntax node)
{
if (!node.Identifier.Span.Contains(span))
yield break;
var parameter = node;
var bodyStatement = parameter.Parent.Parent.ChildNodes().OfType<BlockSyntax>().FirstOrDefault();
if (bodyStatement == null)
yield break;
var parameterSymbol = semanticModel.GetDeclaredSymbol(node);
var type = parameterSymbol.Type;
if (type == null || type.IsValueType || HasNotNullContract(semanticModel, parameterSymbol, bodyStatement))
yield break;
yield return CreateAction(
node.Identifier.Span
, t2 => {
var newBody = bodyStatement.WithStatements(SyntaxFactory.List<StatementSyntax>(new[] { CreateContractRequiresCall(node.Identifier.ToString()) }.Concat(bodyStatement.Statements)));
var newRoot = (CompilationUnitSyntax)root.ReplaceNode((SyntaxNode)bodyStatement, newBody);
if (UsingStatementNotPresent(newRoot)) newRoot = AddUsingStatement(node, newRoot);
return Task.FromResult(document.WithSyntaxRoot(newRoot));
}
, "Add contract requiring parameter must not be null"
);
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:29,代码来源:ContractRequiresNotNullCodeRefactoringProvider.cs
示例3: GetParameterType
public static string GetParameterType(ParameterSyntax parameter)
{
return parameter
.DescendantNodes()
.First(node => node is PredefinedTypeSyntax || node is IdentifierNameSyntax)
.GetFirstToken()
.ValueText;
}
示例4: ParameterTranslation
public ParameterTranslation(ParameterSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
Type = syntax.Type.Get<TypeTranslation>(this);
Identifier = syntax.Identifier.Get(this);
Modifiers = syntax.Modifiers.Get(this);
Default = syntax.Default.Get<EqualsValueClauseTranslation>(this);
}
示例5: VisitParameter
public override SyntaxNode VisitParameter(ParameterSyntax node)
{
return SimplifyNode(
node,
newNode: base.VisitParameter(node),
parentNode: node.Parent,
simplifier: SimplifyParameter);
}
示例6: GetAttributesForParameter
public static IEnumerable<AttributeSyntaxSymbolMapping> GetAttributesForParameter(ParameterSyntax parameter,
SemanticModel semanticModel)
{
return parameter.AttributeLists
.SelectMany(al => al.Attributes)
.Select(attr => new AttributeSyntaxSymbolMapping(attr,
semanticModel.GetSymbolInfo(attr).Symbol as IMethodSymbol))
.Where(attr => attr.Symbol != null);
}
示例7: RemoveHungarianPrefix
private async Task<Solution> RemoveHungarianPrefix(Document document, ParameterSyntax token, CancellationToken cancellationToken)
{
var newName = DehungarianAnalyzer.SuggestDehungarianName(token.Identifier.Text);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var tokenSymbol = semanticModel.GetDeclaredSymbol(token, cancellationToken);
var originalSolution = document.Project.Solution;
var optionSet = originalSolution.Workspace.Options;
var newSolution = await Renamer.RenameSymbolAsync(document.Project.Solution, tokenSymbol, newName, optionSet, cancellationToken).ConfigureAwait(false);
return newSolution;
}
示例8: VisitParameter
public override void VisitParameter(ParameterSyntax node)
{
// ignore parameters in lambdaexpressions
if (node.IsWithinLambda())
return;
var parameter = new Parameter(
node.Identifier.ToString(),
(ITypeSymbol)_semantic.GetSymbolInfo(node.Type).Symbol);
_parameters.Add(parameter);
}
示例9: AppendParameterToMethod
public static MethodDeclarationSyntax AppendParameterToMethod(MethodDeclarationSyntax method,
ParameterSyntax parameter)
{
if (method.ParameterList.Parameters.Any())
{
parameter = parameter.WithLeadingTrivia(SF.Space);
}
return method.WithParameterList(method.ParameterList.AddParameters(parameter));
}
示例10: CreateOperatorDeclaration
protected OperatorDeclarationSyntax CreateOperatorDeclaration(SyntaxKind kind, ParameterSyntax[] parameters, StatementSyntax statement)
{
return SyntaxFactory.OperatorDeclaration(
new SyntaxList<AttributeListSyntax>(),
SyntaxFactory.TokenList(new SyntaxToken[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword) }),
SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.BoolKeyword)),
SyntaxFactory.Token(SyntaxKind.OperatorKeyword),
SyntaxFactory.Token(kind),
SyntaxFactory.ParameterList(SyntaxFactory.SeparatedList(parameters)),
SyntaxFactory.Block(statement),
new SyntaxToken());
}
示例11: ApplyFromODataUriAsync
private async Task<Document> ApplyFromODataUriAsync(Document document, ParameterSyntax node,
CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync();
var newParameter = node.WithAttributeLists(node.AttributeLists.Add(SyntaxFactory.AttributeList(
SyntaxFactory.SingletonSeparatedList<AttributeSyntax>(
SyntaxFactory.Attribute(
SyntaxFactory.IdentifierName("FromODataUri"))))));
var newRoot = root.ReplaceNode(node, newParameter);
var newDocument = document.WithSyntaxRoot(newRoot);
return newDocument;
}
示例12: IntroduceField
private async Task<Solution> IntroduceField(Document document, ParameterSyntax paramDecl, CancellationToken cancellationToken)
{
var rootNode = await document.GetSyntaxRootAsync();
var rewriter = new IntroduceFieldRewriter(paramDecl);
rootNode = rewriter.Visit(rootNode);
var alterConstructorRewriter = new AlterConstructorRewriter(rewriter.GeneratedField, paramDecl.FirstAncestorOrSelf<ConstructorDeclarationSyntax>(), rewriteParams: false);
rootNode = alterConstructorRewriter.Visit(rootNode);
rootNode = Formatter.Format(rootNode, document.Project.Solution.Workspace);
// Produce a new solution that has all references to that type renamed, including the declaration.
return document.WithSyntaxRoot(rootNode).Project.Solution;
}
示例13: Create
public static SourceParameterSymbol Create(
Binder context,
Symbol owner,
TypeSymbol parameterType,
ParameterSyntax syntax,
RefKind refKind,
SyntaxToken identifier,
int ordinal,
bool isParams,
bool isExtensionMethodThis,
DiagnosticBag diagnostics)
{
var name = identifier.ValueText;
var locations = ImmutableArray.Create<Location>(new SourceLocation(identifier));
if (!isParams &&
!isExtensionMethodThis &&
(syntax.Default == null) &&
(syntax.AttributeLists.Count == 0) &&
!owner.IsPartialMethod())
{
return new SourceSimpleParameterSymbol(owner, parameterType, ordinal, refKind, name, locations);
}
if (isParams)
{
// touch the constructor in order to generate proper use-site diagnostics
Binder.ReportUseSiteDiagnosticForSynthesizedAttribute(context.Compilation,
WellKnownMember.System_ParamArrayAttribute__ctor,
diagnostics,
identifier.Parent.GetLocation());
}
var syntaxRef = syntax.GetReference();
return new SourceComplexParameterSymbol(
owner,
ordinal,
parameterType,
refKind,
ImmutableArray<CustomModifier>.Empty,
false,
name,
locations,
syntaxRef,
ConstantValue.Unset,
isParams,
isExtensionMethodThis);
}
示例14: Parameter
public static string Parameter(ParameterSyntax param)
{
if (param.Type == null) return param.Identifier.Text;
if (param.Type is IdentifierNameSyntax)
{
return param.Identifier.Text + ": " + Type(((IdentifierNameSyntax)param.Type).Identifier.Text);
}
// TODO: Double check the variadic parameters handling
if (param.Modifiers.Any(mod => mod.ToString() == "params"))
{
return param.Identifier.Text + ": " + SyntaxNode(((ArrayTypeSyntax)param.Type).ElementType) + "...";
}
return param.Identifier.Text + ": " + SyntaxNode(param.Type);
}
示例15: SourcePrimaryConstructorParameterSymbolWithBackingField
internal SourcePrimaryConstructorParameterSymbolWithBackingField(
Symbol owner,
int ordinal,
TypeSymbol parameterType,
RefKind refKind,
string name,
ImmutableArray<Location> locations,
ParameterSyntax syntax,
ConstantValue defaultSyntaxValue,
bool isParams,
bool isExtensionMethodThis,
DiagnosticBag diagnostics
) : base(owner, ordinal, parameterType, refKind, ImmutableArray<CustomModifier>.Empty, false, name, locations, syntax.GetReference(), defaultSyntaxValue, isParams, isExtensionMethodThis)
{
bool modifierErrors;
var modifiers = SourceMemberFieldSymbol.MakeModifiers(owner.ContainingType, syntax.Identifier, syntax.Modifiers, diagnostics, out modifierErrors, ignoreParameterModifiers: true);
backingField = new BackingField(this, modifiers, modifierErrors, diagnostics);
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:19,代码来源:SourcePrimaryConstructorParameterSymbolWithBackingField.cs