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


C# SyntaxNode.ToString方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.SyntaxNode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxNode.ToString方法的具体用法?C# SyntaxNode.ToString怎么用?C# SyntaxNode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.SyntaxNode的用法示例。


在下文中一共展示了SyntaxNode.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsCreateThreadInLoop

 public void IsCreateThreadInLoop(SyntaxNode node)
 {
     if (node.ToString().Contains("new Thread") && node.Parent.ToString().Contains(".Join"))
     {
         if (Id.ToLower().Contains("test"))
             Helper.WriteInstance(LoopThreadTestFile, Id, node.Parent.ToString());
         else
             Helper.WriteInstance(LoopThreadFile, Id, node.Parent.ToString());
     }
 }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:10,代码来源:ThreadTaskAnalysisWalker.cs

示例2: Visit

        public override void Visit(SyntaxNode node)
        {
            var t = node.Kind();
            if (node.IsKind(SyntaxKind.IdentifierName))
            {
                var name = node.ToString();
                string syntax;
                if (_DefinedOutside.TryGetValue(name, out syntax))
                {
                    _DefinedOutside.Remove(name);
                    sb.Append(syntax);
                }
            }
            /*
            var symbol = _model.GetSymbolInfo(node).Symbol;
            var ca = _model.GetSymbolInfo(node).CandidateSymbols;
            var declaredSymbol = _model.GetDeclaredSymbol(node);

            if (symbol?.Kind == SymbolKind.Field)
            {
                var x = 3;
            }
            if (symbol != null)
            {
                var test = symbol.CanBeReferencedByName;
                var sources = symbol.DeclaringSyntaxReferences;

                if (sources.Any())
                {
                    foreach (var source in sources)
                    {
                        if (source.Span.Start > _end
                            || source.Span.End < _start)
                        {
                            //DefinedOutside.Add(source.GetSyntax().ToFullString());
                        }
                    }
                }
                var locations = symbol?.Locations;
                if (locations.HasValue)
                {
                    /*
                    foreach (var location in locations.Value)
                    {
                        if (location.SourceSpan.Start > _end
                            || location.SourceSpan.End < _start)
                        {
                            DefinedOutside.Add(symbol);
                        }
                    }

                }
            }*/
            base.Visit(node);
        }
开发者ID:AmadeusW,项目名称:SnippetVS,代码行数:55,代码来源:MethodWalker.cs

示例3: IsCreateTaskInLoop

 public void IsCreateTaskInLoop(SyntaxNode node)
 {
     if (node.DescendantNodes().OfType<IdentifierNameSyntax>().Any(a => "StartNew".Equals(a.ToString()))
         && !node.ToString().Contains("Stopwatch"))
     {
         if (Id.ToLower().Contains("test"))
             Helper.WriteInstance(LoopTaskTestFile, Id, node.Parent.ToString());
         else
             Helper.WriteInstance(LoopTaskFile, Id, node.Parent.ToString());
     }
 }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:11,代码来源:ThreadTaskAnalysisWalker.cs

示例4: CreateBaseName

        public static string CreateBaseName(SyntaxNode node, ITypeSymbol type)
        {
            string name = null;

            if (node.IsKind(SyntaxKind.Argument))
                node = ((ArgumentSyntax)node).Expression;

            if (node.IsKind(SyntaxKind.NullLiteralExpression))
                return "o";
            if (node.IsKind(SyntaxKind.InvocationExpression))
                return CreateBaseName(((InvocationExpressionSyntax)node).Expression, type);
            if (node.IsKind(SyntaxKind.IdentifierName))
            {
                name = node.ToString();
            }
            else if (node is MemberAccessExpressionSyntax)
            {
                name = ((MemberAccessExpressionSyntax)node).Name.ToString();
            }
            else if (node is LiteralExpressionSyntax)
            {
                var pe = (LiteralExpressionSyntax)node;
                if (pe.IsKind(SyntaxKind.StringLiteralExpression))
                {
                    name = CreateBaseNameFromString(pe.Token.ToString());
                }
                else
                {
                    return char.ToLower(type.Name[0]).ToString();
                }
            }
            else if (node is ArrayCreationExpressionSyntax)
            {
                name = "arr";
            }
            else
            {
                if (type.TypeKind == TypeKind.Error)
                    return "par";
                name = GuessNameFromType(type);
            }
            var sb = new StringBuilder();
            sb.Append(char.ToLower(name[0]));
            for (int i = 1; i < name.Length; i++)
            {
                var ch = name[i];
                if (char.IsLetterOrDigit(ch) || ch == '_')
                    sb.Append(ch);
            }
            return sb.ToString();
        }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:51,代码来源:RefactoringHelpers.cs

示例5: FixMissingType

        private static void FixMissingType(SyntaxNode node, Scope scope)
        {
            var type = node
                .Ancestors()
                .OfType<TypeDeclarationSyntax>()
                .FirstOrDefault();

            if (type != null)
            {
                var typeScope = scope.GetScope<SyntaxToken, SyntaxNode, SemanticModel>(type);
                if (typeScope != null)
                {
                    SyntaxNode realType = typeScope.get<SyntaxNode>("__tdef" + node.ToString());
                    if (realType != null)
                    {
                        realType = RoslynCompiler.Mark(realType); //make sure not to duplicate nodes

                        var document = scope.GetDocument<SyntaxToken, SyntaxNode, SemanticModel>();
                        document.change(node, RoslynCompiler.ReplaceNode(realType));
                    }
                }
            }
        }
开发者ID:mpmedia,项目名称:Excess,代码行数:23,代码来源:TypeDef.cs

示例6: GetName

			string GetName (SyntaxNode node)
			{
				if (tag is SyntaxTree) {
					var type = node as TypeDeclarationSyntax;
					if (type != null) {
						var sb = new StringBuilder ();
						sb.Append (type.Identifier.ToString ());
						while (type.Parent is TypeDeclarationSyntax) {
							type = type.Parent as TypeDeclarationSyntax;
							sb.Insert (0, type.Identifier + ".");
						}
						return sb.ToString ();
					}
					var delegateDecl = node as DelegateDeclarationSyntax;
					if (delegateDecl != null) {
						var sb = new StringBuilder ();
						sb.Append (delegateDecl.Identifier.ToString ());
						var parentType = delegateDecl.Parent as TypeDeclarationSyntax;
						while (parentType != null) {
							sb.Insert (0, parentType.Identifier + ".");
							parentType = parentType.Parent as TypeDeclarationSyntax;
						}
						return sb.ToString ();
					}
				}
				var accessor = node as AccessorDeclarationSyntax;
				if (accessor != null) {
					if (accessor.Kind () == SyntaxKind.GetAccessorDeclaration)
						return "get";
					if (accessor.Kind () == SyntaxKind.SetAccessorDeclaration)
						return "set";
					if (accessor.Kind () == SyntaxKind.AddAccessorDeclaration)
						return "add";
					if (accessor.Kind () == SyntaxKind.RemoveAccessorDeclaration)
						return "remove";
					return node.ToString ();
				}
				if (node is OperatorDeclarationSyntax)
					return "operator";
				if (node is PropertyDeclarationSyntax)
					return ((PropertyDeclarationSyntax)node).Identifier.ToString ();
				if (node is MethodDeclarationSyntax)
					return ((MethodDeclarationSyntax)node).Identifier.ToString ();
				if (node is ConstructorDeclarationSyntax)
					return ((ConstructorDeclarationSyntax)node).Identifier.ToString ();
				if (node is DestructorDeclarationSyntax)
					return ((DestructorDeclarationSyntax)node).Identifier.ToString ();
				if (node is BaseTypeDeclarationSyntax)
					return ((BaseTypeDeclarationSyntax)node).Identifier.ToString ();

//				if (node is fixeds) {
//					return ((FixedVariableInitializer)node).Name;
//				}
				if (node is VariableDeclaratorSyntax)
					return ((VariableDeclaratorSyntax)node).Identifier.ToString ();
				return node.ToString ();
			}
开发者ID:ZZHGit,项目名称:monodevelop,代码行数:57,代码来源:PathedDocumentTextEditorExtension.cs

示例7: GenerateUnknown

 protected void GenerateUnknown(SyntaxNode node)
 {
     using (QuoteTag(GetLineNumber(node)))
     {
         EncodedText(node.ToString());
     }
 }
开发者ID:nemec,项目名称:roslyn,代码行数:7,代码来源:AbstractMethodXmlBuilder.cs

示例8: Visit

            public override void Visit(SyntaxNode node)
            {
                if (node is ExpressionSyntax)
                {
                    var type = SemanticModel.GetTypeInfo((ExpressionSyntax)node).Type;
                    if (type != null)
                    {
                        Results.AppendLine();
                        Results.Append(node.GetType().Name);
                        Results.Append(" ");
                        Results.Append(node.ToString());
                        Results.Append(" has type ");
                        Results.Append(type.ToDisplayString());
                    }
                }

                base.Visit(node);
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:FAQ.cs

示例9: OutputNode

		public async Task<string> OutputNode (SyntaxNode node, CancellationToken cancellationToken = default(CancellationToken))
		{
			node = Formatter.Format (node, TypeSystemService.Workspace, FormattingOptions, cancellationToken);

			var text = Editor.Text;
			string nodeText = node.ToString ();
			text = text.Insert (offset, nodeText);

			var backgroundDocument = DocumentContext.AnalysisDocument.WithText (SourceText.From (text));

			var currentRoot = await backgroundDocument.GetSyntaxRootAsync (cancellationToken).ConfigureAwait (false);

			// add formatter & simplifier annotations 
			var oldNode = currentRoot.FindNode (TextSpan.FromBounds(offset, offset + nodeText.Length));
			currentRoot = currentRoot.ReplaceNode (oldNode, oldNode.WithAdditionalAnnotations (Formatter.Annotation, Simplifier.Annotation)); 

			// get updated node
			node = currentRoot.FindNode (TextSpan.FromBounds(offset, offset + nodeText.Length));
			currentRoot = currentRoot.TrackNodes (node);

			backgroundDocument = backgroundDocument.WithSyntaxRoot (currentRoot);
			backgroundDocument = await Formatter.FormatAsync (backgroundDocument, Formatter.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
			backgroundDocument = await Simplifier.ReduceAsync (backgroundDocument, Simplifier.Annotation, cancellationToken: cancellationToken).ConfigureAwait(false);
			var newRoot = await backgroundDocument.GetSyntaxRootAsync (cancellationToken).ConfigureAwait (false);

			var formattedNode = newRoot.GetCurrentNode (node);
			if (formattedNode == null) {
				LoggingService.LogError ("Fatal error: Can't find current formatted node in code generator document.");
				return nodeText;
			}
			return formattedNode.ToString ();
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:32,代码来源:CodeGenerationOptions.cs

示例10: HandleTypeParameterCase

		ParameterHintingResult HandleTypeParameterCase(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken)
		{
			var result = new ParameterHintingResult(node.SpanStart);
			string typeName;
			var gns = node as GenericNameSyntax;
			if (gns != null) {
				typeName = gns.Identifier.ToString ();
			} else {
				typeName = node.ToString ();
			}

			foreach (var cand in semanticModel.LookupSymbols (node.SpanStart).OfType<INamedTypeSymbol> ()) {
				if (cand.TypeParameters.Length == 0)
					continue;
				if (cand.Name == typeName || cand.GetFullName () == typeName)
					result.AddData(factory.CreateTypeParameterDataProvider(cand));
			}

			if (result.Count == 0) {
				foreach (var cand in semanticModel.LookupSymbols (node.SpanStart).OfType<IMethodSymbol> ()) {
					if (cand.TypeParameters.Length == 0)
						continue;
					if (cand.Name == typeName)
						result.AddData (factory.CreateTypeParameterDataProvider (cand));
				}
			}
			return result;
		}
开发者ID:pjcollins,项目名称:monodevelop,代码行数:28,代码来源:ParameterHintingEngine.cs

示例11: AddErrorTrace

 /// <summary>
 /// Adds new error trace to the trace for
 /// the specified syntax node.
 /// </summary>
 /// <param name="syntaxNode">SyntaxNode</param>
 internal void AddErrorTrace(SyntaxNode syntaxNode)
 {
     var errorTraceStep = new ErrorTraceStep(syntaxNode.ToString(),
         syntaxNode.SyntaxTree.FilePath, syntaxNode.SyntaxTree.GetLineSpan(
             syntaxNode.Span).StartLinePosition.Line + 1);
     this.ErrorTrace.Add(errorTraceStep);
 }
开发者ID:yonglehou,项目名称:PSharp,代码行数:12,代码来源:TraceInfo.cs

示例12: CollectExtensionSuggestions

        private IEnumerable<IPackageIndexModelInfo> CollectExtensionSuggestions(SyntaxNode node, IEnumerable<TargetFrameworkMetadata> distinctTargetFrameworks)
        {
            string entityName;
            IEnumerable<IPackageIndexModelInfo> potentialSuggestions = null;
            if (_syntaxHelper.IsExtension(node))
            {
                entityName = node.ToString().NormalizeGenericName();

                potentialSuggestions = _packageSearcher.SearchExtension(entityName);
            }

            if (potentialSuggestions == null || !potentialSuggestions.Any())
            {
                return Enumerable.Empty<IPackageIndexModelInfo>();
            }

            return TargetFrameworkHelper.GetSupportedPackages(potentialSuggestions,
                                                              distinctTargetFrameworks, 
                                                              allowHigherVersions: true);
        }
开发者ID:digideskio,项目名称:NuGet.PackageIndex,代码行数:20,代码来源:AddPackageAnalyzer.cs

示例13: CollectTypeSuggestions

        private IEnumerable<IPackageIndexModelInfo> CollectTypeSuggestions(SyntaxNode node, IEnumerable<TargetFrameworkMetadata> distinctTargetFrameworks)
        {
            var potentialSuggestions = new List<IPackageIndexModelInfo>();
            if (_syntaxHelper.IsType(node))
            {
                var entityNamesToSearchFor = new List<string>();
                var entityName = node.ToString().NormalizeGenericName();
                entityNamesToSearchFor.Add(entityName);

                if (_syntaxHelper.IsAttribute(node) && !entityName.EndsWith("Attribute"))
                {
                    entityNamesToSearchFor.Add(entityName + "Attribute");
                }

                foreach (var entity in entityNamesToSearchFor)
                {
                    var suggestions = _packageSearcher.SearchType(entity);
                    if (suggestions != null)
                    {
                        potentialSuggestions.AddRange(suggestions);
                    }
                }
            }

            if (potentialSuggestions == null || !potentialSuggestions.Any())
            {
                return Enumerable.Empty<IPackageIndexModelInfo>();
            }

            return TargetFrameworkHelper.GetSupportedPackages(potentialSuggestions,
                                                              distinctTargetFrameworks, 
                                                              allowHigherVersions: true);
        }       
开发者ID:digideskio,项目名称:NuGet.PackageIndex,代码行数:33,代码来源:AddPackageAnalyzer.cs

示例14: IsMachineMethod

        /// <summary>
        /// True if the given syntax node is a machine method.
        /// </summary>
        /// <param name="node">SyntaxNode</param>
        /// <returns>Boolean value</returns>
        protected bool IsMachineMethod(SyntaxNode node)
        {
            var result = false;

            MachineDeclaration machine = null;
            if (!this.TryGetParentMachine(node, out machine))
            {
                return result;
            }

            result = machine.MethodDeclarations.
                Any(s => s.Identifier.TextUnit.Text.Equals(node.ToString()));

            if (!result)
            {
                result = machine.FieldDeclarations.
                    Any(s => s.Identifier.TextUnit.Text.Equals(node.ToString()));
            }

            return result;
        }
开发者ID:jerickmsft,项目名称:PSharp,代码行数:26,代码来源:PSharpRewriter.cs

示例15: GetAnonymousTypePropertyName

 static string GetAnonymousTypePropertyName(SyntaxNode expr)
 {
     var mAccess = expr as MemberAccessExpressionSyntax;
     return mAccess != null ? mAccess.Name.ToString() : expr.ToString();
 }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:5,代码来源:RedundantAnonymousTypePropertyNameAnalyzer.cs


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