当前位置: 首页>>代码示例>>C#>>正文


C# Syntax.ParameterSyntax类代码示例

本文整理汇总了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;
        }
开发者ID:Vossekop,项目名称:code-cracker,代码行数:35,代码来源:IntroduceFieldFromConstructorCodeFixProvider.cs

示例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;
 }
开发者ID:hakenr,项目名称:RoslynCodeRefactoringPlayground,代码行数:8,代码来源:RoslynHelpers.cs

示例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);
    
 }
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:8,代码来源:ParameterTranslation.cs

示例5: VisitParameter

 public override SyntaxNode VisitParameter(ParameterSyntax node)
 {
     return SimplifyNode(
         node,
         newNode: base.VisitParameter(node),
         parentNode: node.Parent,
         simplifier: SimplifyParameter);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:8,代码来源:CSharpMiscellaneousReducer.Rewriter.cs

示例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);
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:9,代码来源:AttributeSyntaxSymbolMapping.cs

示例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;
 }        
开发者ID:CaptiveAire,项目名称:dehungarian,代码行数:10,代码来源:CodeFixProvider.cs

示例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);
 }
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:10,代码来源:ParameterSyntaxReader.cs

示例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));
        }
开发者ID:cdsalmons,项目名称:OrleansTemplates,代码行数:10,代码来源:RoslynUtils.cs

示例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());
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:12,代码来源:CA2231CSharpCodeFixProvider.cs

示例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;

        }
开发者ID:DualBrain,项目名称:DotNetAnalyzers,代码行数:15,代码来源:ODataFromODataUriCodeFix.cs

示例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;
        }
开发者ID:yohney,项目名称:common-refactorings-plugin,代码行数:15,代码来源:IntroduceFieldRefactoringProvider.cs

示例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);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:48,代码来源:SourceParameterSymbol.cs

示例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);
        }
开发者ID:UIKit0,项目名称:SharpSwift,代码行数:17,代码来源:ParameterSyntaxParser.cs

示例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


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.ParameterSyntax类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。