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


C# Syntax.IdentifierNameSyntax类代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax的典型用法代码示例。如果您正苦于以下问题:C# IdentifierNameSyntax类的具体用法?C# IdentifierNameSyntax怎么用?C# IdentifierNameSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IdentifierNameSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了IdentifierNameSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitIdentifierName

 public override void VisitIdentifierName(IdentifierNameSyntax node)
 {
     base.VisitIdentifierName(node);
     var symbol = nodeContext.SemanticModel.GetSymbolInfo(node).Symbol;
     if (symbol.IsKind(SymbolKind.TypeParameter))
         UsedTypeParameters.Add(symbol);
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:7,代码来源:UnusedTypeParameterAnalyzer.cs

示例2: processIdentifierName

        /// <summary>
        /// Examines the identifier and if applicable, creates an instance of ObjectInformation
        /// which will be consumed later by the SyntaxBuilder
        /// </summary>
        /// <param name="node"></param>
        private void processIdentifierName(IdentifierNameSyntax node)
        {
            var symbol = _model.GetSymbolInfo(node).Symbol;
            var type = _model.GetTypeInfo(node).Type;
            if (type == null || symbol == null)
            {
                // We need a symbol
                // Method names are an example of identifiers with no types, and we ignore them
                return;
            }
            if (node.IsVar)
            {
                return;
            }
            if (symbol != null)
            {
                var typeName = type?.Name ?? String.Empty;
                // Handle generics (TODO: recursively go through all levels)
                var namedType = type as INamedTypeSymbol;
                if (namedType != null)
                {
                    List<string> argumentNames = new List<string>();
                    foreach (var argument in namedType.TypeArguments)
                    {
                        var argumentName = argument.Name;
                        argumentNames.Add(argumentName);
                    }
                    if (argumentNames.Any())
                    {
                        typeName = $"{type?.Name}<{String.Join(", ", argumentNames)}>";
                    }
                }

                // Attempt to remove trivial identifiers like String.Empty
                var definitionName = symbol.OriginalDefinition.ToDisplayString();
                var actualName = typeName + "." + symbol.MetadataName;
                if (String.Compare(definitionName, actualName, ignoreCase: true) == 0)
                {
                    // This identifier is already well defined in the snippet.
                    return;
                }

                foreach (var location in symbol.OriginalDefinition.Locations)
                {
                    // Process only nodes defined outside of the target range
                    if (!location.IsInSource || !(location.SourceSpan.Start < _end && location.SourceSpan.End > _start))
                    {
                        var objectInfo = new ObjectInformation()
                        {
                            Identifier = node?.Identifier.ToString() ?? String.Empty,
                            TypeName = typeName ?? String.Empty,
                            Namespace = type?.ContainingNamespace?.ToString() ?? String.Empty,
                            AssemblyName = type?.ContainingAssembly?.Name ?? String.Empty,
                            Kind = symbol.Kind,
                        };
                        definedWithinSnippet.Add(objectInfo);
                    }
                }
            }
        }
开发者ID:CodeConnect,项目名称:gistify,代码行数:65,代码来源:DiscoveryWalker.cs

示例3: VisitIdentifierName

        public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node)
        {
            if (node.Identifier.ToString() == renameFrom.ToString())
                return SyntaxFactory.IdentifierName(renameTo);

            return base.VisitIdentifierName(node);
        }
开发者ID:x335,项目名称:WootzJs,代码行数:7,代码来源:IdentifierRenamer.cs

示例4: InsertStopwatchToMeasureTime

        private async Task<Document> InsertStopwatchToMeasureTime(Document document, IdentifierNameSyntax node, CancellationToken cancellationToken) {
            SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken);
            var nodes = new List<Tuple<SyntaxNode, SyntaxNode>>();

            SyntaxNode nodeLine = GetRootNodeOfLine(node);
            SyntaxNode newNode = CommentLine(nodeLine);
            newNode = newNode.WithTrailingTrivia(newNode.GetTrailingTrivia()
                .AddRange(nodeLine.GetLeadingTrivia())
                .Add(SyntaxFactory.SyntaxTrivia(SyntaxKind.SingleLineCommentTrivia, "timer.Stop();"))
                .Add(SyntaxFactory.EndOfLine(Environment.NewLine))
                .AddRange(nodeLine.GetLeadingTrivia())
                .Add(SyntaxFactory.SyntaxTrivia(SyntaxKind.SingleLineCommentTrivia, "TimeSpan elapsed = timer.Elapsed;"))
                .Add(SyntaxFactory.EndOfLine(Environment.NewLine)));

            nodes.Add(new Tuple<SyntaxNode, SyntaxNode>(nodeLine, newNode));

            var methodDeclaration = node.FirstAncestorOfType(typeof(MethodDeclarationSyntax)) as MethodDeclarationSyntax;
            if (semanticModel == null) { return document; }
            SyntaxNode firstGetTime = TimeMeasurementCodeAnalyzer.GetNodesUsedToGetCurrentTime(semanticModel, methodDeclaration).First();
            nodeLine = GetRootNodeOfLine(firstGetTime);
            newNode = CommentLine(nodeLine);
            newNode = newNode.WithTrailingTrivia(newNode.GetTrailingTrivia()
                .AddRange(nodeLine.GetLeadingTrivia())
                .Add(SyntaxFactory.SyntaxTrivia(SyntaxKind.SingleLineCommentTrivia, "var timer = Stopwatch.StartNew();"))
                .Add(SyntaxFactory.EndOfLine(Environment.NewLine)));

            nodes.Add(new Tuple<SyntaxNode, SyntaxNode>(nodeLine, newNode));

            document = await this.ReplaceNodesInDocumentAsync(document, cancellationToken, nodes.ToArray());
            return await this.CheckNamespaceUsageAsync(document, cancellationToken, "System.Diagnostics");
        }
开发者ID:vuder,项目名称:CodingStandardCodeAnalyzers,代码行数:31,代码来源:TimeMeasurementCodeAnalyzerCodeFixProvider.cs

示例5: VisitIdentifierName

        public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node)
        {
            if (!(node.Parent is MemberAccessExpressionSyntax) || ((MemberAccessExpressionSyntax)node.Parent).Expression == node)
            {
                if (node.GetContainingMethod() == null)
                {
                    return base.VisitIdentifierName(node);
                }

                var containingType = node.GetContainingType();
                if (containingType == null || !containingType.Name.StartsWith(enclosingTypeName))
                    return node;

                var symbol = semanticModel.GetSymbolInfo(node).Symbol;
                var isObjectInitializer = node.Parent != null && node.Parent.Parent is InitializerExpressionSyntax;
                if (!isObjectInitializer)
                {
                    if (symbol == null || (new[] { SymbolKind.Field, SymbolKind.Event, SymbolKind.Method, SymbolKind.Property }.Contains(symbol.Kind) && !symbol.ContainingType.Name.StartsWith(enclosingTypeName) && !symbol.IsStatic))
                    {
                        return SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName("_this"), node);
                    }
                }
            }
            return base.VisitIdentifierName(node);
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:25,代码来源:StatMachineGeneratorFixer.cs

示例6: AnalyzeTypeNode

		private static void AnalyzeTypeNode(
			SyntaxNodeAnalysisContext context,
			Location location,
			IdentifierNameSyntax typeNode) {
			if (typeNode == null || typeNode.IsVar) return;

			var classSymbol = context.SemanticModel.GetSymbolInfo(typeNode).Symbol as INamedTypeSymbol;
			if (classSymbol == null) return;
			if (classSymbol.TypeKind != TypeKind.Class) return;
			if (classSymbol.AllInterfaces.Count() != 1) return;
			if (!classSymbol.CanBeReferencedByName) return;

			var interfaceSymbol = classSymbol.AllInterfaces.Single();
			if (!interfaceSymbol.CanBeReferencedByName) return;

			context.ReportDiagnostic(
				Diagnostic.Create(
					Rule,
					location,
					properties: ImmutableDictionary.Create<string, string>()
						.Add("interfaceName", interfaceSymbol.Name)
						.Add("interfaceNamespace", interfaceSymbol.ContainingNamespace.Name)
						.Add("className", classSymbol.Name),
					messageArgs: new[] { classSymbol.Name, interfaceSymbol.Name }
			));
		}
开发者ID:vlova,项目名称:RoslynSlides,代码行数:26,代码来源:UsageOfClassInsteadOfInterfaceAnalyzer.cs

示例7: IntroduceLocalDeclarationIntoLambda

		private Document IntroduceLocalDeclarationIntoLambda(
			SemanticDocument document,
			ExpressionSyntax expression,
			IdentifierNameSyntax newLocalName,
			LocalDeclarationStatementSyntax declarationStatement,
			SyntaxNode oldLambda,
			bool allOccurrences,
			CancellationToken cancellationToken)
		{
			var oldBody = oldLambda is ParenthesizedLambdaExpressionSyntax
				? (ExpressionSyntax)((ParenthesizedLambdaExpressionSyntax)oldLambda).Body
			                                                                        : (ExpressionSyntax)((SimpleLambdaExpressionSyntax)oldLambda).Body;

			var rewrittenBody = Rewrite(
				document, expression, newLocalName, document, oldBody, allOccurrences, cancellationToken);

			var delegateType = document.SemanticModel.GetTypeInfo(oldLambda, cancellationToken).ConvertedType as INamedTypeSymbol;

			var newBody = delegateType != null && delegateType.DelegateInvokeMethod != null && delegateType.DelegateInvokeMethod.ReturnsVoid
			                                                  ? SyntaxFactory.Block(declarationStatement)
			                                                  : SyntaxFactory.Block(declarationStatement, SyntaxFactory.ReturnStatement(rewrittenBody));

			newBody = newBody.WithAdditionalAnnotations(Formatter.Annotation);

			var newLambda = oldLambda is ParenthesizedLambdaExpressionSyntax
				? ((ParenthesizedLambdaExpressionSyntax)oldLambda).WithBody(newBody)
			                                                      : (SyntaxNode)((SimpleLambdaExpressionSyntax)oldLambda).WithBody(newBody);

			var newRoot = document.Root.ReplaceNode(oldLambda, newLambda);
			return document.Document.WithSyntaxRoot(newRoot);
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:31,代码来源:CSharpIntroduceVariableService_IntroduceLocal.cs

示例8: RewriteExpression

        /// <summary>
        /// Rewrites the expression with a field access expression.
        /// </summary>
        /// <param name="node">IdentifierNameSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteExpression(IdentifierNameSyntax node)
        {
            SyntaxNode rewritten = node;

            if (!base.IsInStateScope(rewritten) ||
                !(base.IsMachineField(rewritten) || base.IsMachineMethod(rewritten)))
            {
                return rewritten;
            }

            if (!(rewritten.Parent is MemberAccessExpressionSyntax) &&
                !(rewritten.Parent is ObjectCreationExpressionSyntax) &&
                !(rewritten.Parent is TypeOfExpressionSyntax))
            {
                var text = "this." + node.ToString();

                rewritten = SyntaxFactory.ParseExpression(text);
                rewritten = rewritten.WithTriviaFrom(node);
            }

            if ((rewritten.Parent is MemberAccessExpressionSyntax) &&
                (rewritten.Parent as MemberAccessExpressionSyntax).Expression is IdentifierNameSyntax &&
                ((rewritten.Parent as MemberAccessExpressionSyntax).Expression as IdentifierNameSyntax).
                IsEquivalentTo(node))
            {
                var text = "this." + node.ToString();

                rewritten = SyntaxFactory.ParseExpression(text);
                rewritten = rewritten.WithTriviaFrom(node);
            }

            return rewritten;
        }
开发者ID:jerickmsft,项目名称:PSharp,代码行数:38,代码来源:FieldAccessRewriter.cs

示例9: GetMissingEnumMembers

        //--- Class Methods ---
        public static IEnumerable<ISymbol> GetMissingEnumMembers(SwitchStatementSyntax switchNode, SemanticModel semanticModel, out IdentifierNameSyntax switchVariable)
        {
            // TODO (2016-02-25, steveb): what if the swich calls a function instead?
            switchVariable = switchNode.Expression as IdentifierNameSyntax;
            if(switchVariable == null) {
                return Enumerable.Empty<ISymbol>();
            }
            var switchVariableTypeInfo = semanticModel.GetTypeInfo(switchVariable);

            // check if we are switching over an enum
            if((switchVariableTypeInfo.Type != null) && (switchVariableTypeInfo.Type.TypeKind == TypeKind.Enum)) {

                // get all the enum values
                var enumMembers = switchVariableTypeInfo.Type.GetMembers().Where(x => x.Kind == SymbolKind.Field).ToImmutableArray();

                // get all case statements
                var caseSwitchLabels = switchNode.Sections
                    .SelectMany(section => section.Labels)
                    .Select(label => label.DescendantNodes().OfType<MemberAccessExpressionSyntax>().FirstOrDefault())
                    .Where(memberAccess => memberAccess != null)
                    .Select(memberAccess => semanticModel.GetSymbolInfo(memberAccess).Symbol)
                    .ToImmutableHashSet();

                // make sure we have all cases covered
                return enumMembers.Where(x => !caseSwitchLabels.Contains(x)).ToImmutableArray();
            }
            return Enumerable.Empty<ISymbol>();
        }
开发者ID:MindTouch,项目名称:MindTouchRoslynAnalyzers,代码行数:29,代码来源:EnumSwitchAnalysis.cs

示例10: NavInvocationAnnotation

 protected NavInvocationAnnotation(NavTaskAnnotation taskAnnotation, 
                                   IdentifierNameSyntax identifier): base(taskAnnotation) {
     if(identifier == null) {
         throw new ArgumentNullException(nameof(identifier));
     }
     Identifier = identifier;
 }
开发者ID:IInspectable,项目名称:Nav.Language.Extensions,代码行数:7,代码来源:NavInvocationAnnotation.cs

示例11: VisitIdentifierName

 /// <summary>
 /// Called by the base class. Processes identifiers that are in desired range.
 /// </summary>
 /// <param name="node"></param>
 public override void VisitIdentifierName(IdentifierNameSyntax node)
 {
     // Process only nodes in the target range
     if (node.Span.Start < _end && node.Span.End > _start)
     {
         processIdentifierName(node);
     }
 }
开发者ID:CodeConnect,项目名称:gistify,代码行数:12,代码来源:DiscoveryWalker.cs

示例12: RewriteExpression

        /// <summary>
        /// Rewrites the expression with a trigger expression.
        /// </summary>
        /// <param name="node">IdentifierNameSyntax</param>
        /// <returns>SyntaxNode</returns>
        private SyntaxNode RewriteExpression(IdentifierNameSyntax node)
        {
            var text = "this.ReceivedEvent";
            var rewritten = SyntaxFactory.ParseExpression(text);
            rewritten = rewritten.WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:huangpf,项目名称:PSharp,代码行数:13,代码来源:TriggerRewriter.cs

示例13: ExceptionReference

        public ExceptionReference(ISymbol symbol, IdentifierNameSyntax identifier)
        {
            Contract.Requires(symbol != null);
            Contract.Requires(identifier != null);

            Symbol = symbol;
            Identifier = identifier;
        }
开发者ID:SergeyTeplyakov,项目名称:ErrorProne.NET,代码行数:8,代码来源:Helpers.cs

示例14: CreateYieldReturnIfNotCompleted

 /// <summary>
 /// Create If statement that execute yield return if not completed the <see cref="Task"/> or <see cref="Task{T}"/> object.
 /// </summary>
 /// <remarks>
 /// if (!task.IsCompleted)
 ///     yield return task;
 /// </remarks>
 private static SyntaxNode CreateYieldReturnIfNotCompleted(IdentifierNameSyntax task)
 {
     return SyntaxFactory.IfStatement(
         SyntaxFactory.PrefixUnaryExpression(SyntaxKind.LogicalNotExpression, SyntaxFactory.Token(SyntaxKind.ExclamationToken),
             SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, task, SyntaxFactory.IdentifierName("IsCompleted"))
         ),
         SyntaxFactory.YieldStatement(SyntaxKind.YieldReturnStatement, task)
     );
 }
开发者ID:endo0407,项目名称:IteratorTasks,代码行数:16,代码来源:SyntaxExtensions.cs

示例15: RewriteType

        /// <summary>
        /// Rewrites the type with a halt event type.
        /// </summary>
        /// <param name="node">IdentifierNameSyntax</param>
        /// <returns>ExpressionSyntax</returns>
        private ExpressionSyntax RewriteType(IdentifierNameSyntax node)
        {
            var text = typeof(Halt).FullName;

            var rewritten = SyntaxFactory.ParseName(text);
            rewritten = rewritten.WithTriviaFrom(node);

            return rewritten;
        }
开发者ID:yonglehou,项目名称:PSharp,代码行数:14,代码来源:HaltEventRewriter.cs


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