當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。