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


C# SyntaxNode.ToFullString方法代码示例

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


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

示例1: EvaluateImpl

		protected override EvaluationResult EvaluateImpl(SyntaxNode node)
		{
			var classDeclaration = (ClassDeclarationSyntax)node;
			if (classDeclaration.BaseList != null && classDeclaration.BaseList.Types.Any(t => (t.Type is IdentifierNameSyntax) && ((IdentifierNameSyntax)t.Type).Identifier.ValueText.Contains("IDisposable")))
			{
				var methods = classDeclaration.ChildNodes().OfType<MethodDeclarationSyntax>()
					.Where(m => m.Identifier.ValueText == "Dispose")
					.Where(m =>
						{
							var predefinedType = SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.BoolKeyword));
							return m.ParameterList.Parameters.Count == 0
										   || (m.ParameterList.Parameters.Count == 1 && m.ParameterList.Parameters[0].Type.EquivalentTo(predefinedType));
						}).AsArray();
				var destructor = classDeclaration
					.ChildNodes()
					.OfType<DestructorDeclarationSyntax>()
					.FirstOrDefault(d => d.Body.ChildNodes().Any(InvokesDispose));
				if (methods.Length < 2 || destructor == null)
				{
					return new EvaluationResult
					{
						Snippet = node.ToFullString()
					};
				}
			}

			return null;
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:28,代码来源:IncorrectDisposableImplementation.cs

示例2: EvaluateImpl

		protected override EvaluationResult EvaluateImpl(SyntaxNode node)
		{
			return new EvaluationResult
					   {
						   Snippet = node.ToFullString()
					   };
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:7,代码来源:GotoStatementErrorRule.cs

示例3: EquivalentTo

		public static bool EquivalentTo(this SyntaxNode node1, SyntaxNode node2)
		{
			if (node1 == null || node2 == null)
			{
				return node1 == null && node2 == null;
			}

			return node1.RawKind == node2.RawKind && node1.ToFullString().Trim().Equals(node2.ToFullString().Trim());
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:9,代码来源:RoslynExtensions.cs

示例4: EvaluateImpl

		protected override EvaluationResult EvaluateImpl(SyntaxNode node)
		{
			var ns = FindNamespaceParent(node);
			if (ns == null)
			{
				return new EvaluationResult
					   {
						   Snippet = node.ToFullString()
					   };
			}

			return null;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:13,代码来源:TypeMustBeDeclaredInNamespaceRule.cs

示例5: EvaluateImpl

		protected override EvaluationResult EvaluateImpl(SyntaxNode node)
		{
			var syntax = (FieldDeclarationSyntax)node;
			if (syntax.Modifiers.Any(SyntaxKind.PublicKeyword))
			{
				return new EvaluationResult
						   {
							   Snippet = node.ToFullString()
						   };
			}

			return null;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:13,代码来源:NoPublicFieldsRule.cs

示例6: EvaluateImpl

		protected override Task<EvaluationResult> EvaluateImpl(SyntaxNode node, SemanticModel semanticModel, Solution solution)
		{
			if (IsEmptyFinalizer(node, semanticModel))
			{
				var result = new EvaluationResult
								 {
									 Snippet = node.ToFullString()
								 };

				return Task.FromResult(result);
			}

			return Task.FromResult<EvaluationResult>(null);
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:14,代码来源:EmptyFinalizerRule.cs

示例7: EvaluateImpl

		protected override EvaluationResult EvaluateImpl(SyntaxNode node)
		{
			// Roslyn does not handle async await keywords.
			var diagnostics = node.GetDiagnostics();
			if (diagnostics.Any(d => d.Severity != DiagnosticSeverity.Info))
			{
				return new EvaluationResult
						   {
							   Snippet = node.ToFullString()
						   };
			}

			return null;
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:14,代码来源:CompilationDiagnosticsEvaluation.cs

示例8: EvaluateImpl

		protected override EvaluationResult EvaluateImpl(SyntaxNode node)
		{
			var memberAccess = (MemberAccessExpressionSyntax)node;
			if (memberAccess.Expression.IsKind(SyntaxKind.InvocationExpression)
				&& memberAccess.Expression.GetText().ToString().Trim() == "MethodBase.GetCurrentMethod()")
			{
				return new EvaluationResult
						   {
							   Snippet = node.ToFullString()
						   };
			}

			return null;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:14,代码来源:ReflectionToResolveMethodNameRule.cs

示例9: Visit

 // Standard script code
 public override void Visit(SyntaxNode node)
 {
     if (node is CompilationUnitSyntax)
     {
         // Top-level compilation unit
         base.Visit(node);
     }
     else if (node is UsingDirectiveSyntax)
     {
         // Using directive
         Add(node.ToFullString(), _usingDirectives, false);
     }
     else if (node is BaseTypeDeclarationSyntax)
     {
         // Type declaration
         Add(node.ToFullString(), _typeDeclarations);
     }
     else if (node is MethodDeclarationSyntax)
     {
         // Method (standard or extension)
         ParameterSyntax firstParameter = ((MethodDeclarationSyntax)node).ParameterList.Parameters.FirstOrDefault();
         if (firstParameter != null && firstParameter.GetFirstToken().Kind() == SyntaxKind.ThisKeyword)
         {
             Add(node.ToFullString(), _extensionMethodDeclarations);
         }
         else
         {
             Add(node.ToFullString(), _methodDeclarations);
         }
     }
     else
     {
         // Everything else is standard script code
         Add(node?.ToFullString(), _scriptCode);
     }
 }
开发者ID:ibebbs,项目名称:Wyam,代码行数:37,代码来源:LiftingWalker.cs

示例10: EvaluateImpl

		protected override async Task<EvaluationResult> EvaluateImpl(SyntaxNode node, SemanticModel semanticModel, Solution solution)
		{
			var symbol = semanticModel.GetDeclaredSymbol(node);
			var callers = await solution.FindReferences(symbol).ConfigureAwait(false);

			if (!callers.Locations.Any(x => IsNotAssignment(x.Location)))
			{
				return new EvaluationResult
					   {
						   Snippet = node.ToFullString()
					   };
			}

			return null;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:15,代码来源:UnusedCodeRule.cs

示例11: EvaluateImpl

		protected override EvaluationResult EvaluateImpl(SyntaxNode node)
		{
			var statement = (ThrowStatementSyntax)node;
			var exceptionCreation = statement.Expression as ObjectCreationExpressionSyntax;
			if (exceptionCreation != null)
			{
				var exceptionType = exceptionCreation.Type as IdentifierNameSyntax;
				if (exceptionType != null && exceptionType.Identifier.ValueText.EndsWith("NotImplementedException"))
				{
					return new EvaluationResult
					{
						Snippet = node.ToFullString()
					};
				}
			}

			return null;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:18,代码来源:NoNotImplementedExceptionRule.cs

示例12: EvaluateImpl

		protected override async Task<EvaluationResult> EvaluateImpl(SyntaxNode node, SemanticModel semanticModel, Solution solution)
		{
			var referenceTasks = GetSymbols(node, semanticModel)
				.Select(solution.FindReferences);
			var references = (await Task.WhenAll(referenceTasks).ConfigureAwait(false))
				.SelectMany(x => x.Locations)
				.Select(x => x.Location.SourceTree.GetRoot().FindToken(x.Location.SourceSpan.Start))
				.Select(x => x.Parent)
				.Where(x => x != null)
				.Select(x => new { Value = x, Parent = x.Parent })
				.Where(x => IsNotAssignment(x.Parent, x.Value))
				.AsArray();

			if (!references.Any())
			{
				return new EvaluationResult
					   {
						   Snippet = node.ToFullString()
					   };
			}

			return null;
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:23,代码来源:UnreadValueRule.cs

示例13: EvaluateImpl

		protected override async Task<EvaluationResult> EvaluateImpl(SyntaxNode node, SemanticModel semanticModel, Solution solution)
		{
			var classDeclaration = (ClassDeclarationSyntax)node;
			var symbol = (ITypeSymbol)ModelExtensions.GetDeclaredSymbol(semanticModel, classDeclaration);
			var members = symbol.GetMembers();

			var memberCount = members.Count(x => MemberKinds.Contains(x.Kind));
			if (memberCount < _threshold)
			{
				return null;
			}

			var fields = members.Where(x => x.Kind == SymbolKind.Field).AsArray();
			var fieldCount = fields.Length;

			if (fieldCount < _threshold)
			{
				return null;
			}

			var references = await Task.WhenAll(fields.Select(solution.FindReferences)).ConfigureAwait(false);
			var sumFieldUsage = (double)references.Sum(r => r.Locations.Count());

			var lcomhs = (memberCount - (sumFieldUsage / fieldCount)) / (memberCount - 1);
			if (lcomhs < 1)
			{
				return null;
			}

			var snippet = node.ToFullString();
			return new EvaluationResult
				   {
					   Snippet = snippet
				   };
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:35,代码来源:LackOfCohesionOfMethodsRule.cs

示例14: Visit

        public override SyntaxNode Visit(SyntaxNode node)
        {
            Context.LastNode = node;
            try
            {

                if (node is NameEqualsSyntax)
                    return (node);

               

                //			SyntaxNode visit; //Needs update
                //                     if (FixPropertyUnaryExpressions(node, out visit))
                //                return visit;
                  if (node is IdentifierNameSyntax &&
                   //   (node.Parent is ExpressionSyntax || node.Parent is MethodDeclarationSyntax || node.Parent is PropertyDeclarationSyntax
                     // || node.Parent is BlockSyntax) &&
                      !(node.Parent.Parent is InitializerExpressionSyntax) &&
                      !(node.Parent is QualifiedNameSyntax) && !(node.Parent is MemberAccessExpressionSyntax) && !(node.Parent is ThisExpressionSyntax))
                  {
                      //Lets fully qualify these so that we can have property code working
                      var symbolInfo = _semanticModel.GetSymbolInfo(node);

                      if (symbolInfo.Symbol != null &&
                          (symbolInfo.Symbol.Kind == SymbolKind.Field || symbolInfo.Symbol.Kind == SymbolKind.Property))
                      {
                          if (symbolInfo.Symbol.ContainingType != null && symbolInfo.Symbol.IsStatic)
                          {
                              var newName = symbolInfo.Symbol.ContainingType.GetFullNameCSharp() + "." +
                                            symbolInfo.Symbol.Name;
                              return SyntaxFactory.ParseExpression(newName);
                          }
                          else
                          {

                              var firstParent =
                                  TypeProcessor.GetDeclaredSymbol(node.Ancestors().OfType<BaseTypeDeclarationSyntax>().First());
                              //_semanticModel.GetSymbolInfo(node.Ancestors().OfType<BaseTypeDeclarationSyntax>().First());
                              if (symbolInfo.Symbol.ContainingType != null && !symbolInfo.Symbol.IsStatic && symbolInfo.Symbol.ContainingType == firstParent)
                                  return SyntaxFactory.ParseExpression("this." + symbolInfo.Symbol.Name);
                          }
                          return base.Visit(node);
                      }
                  }

                if (node is MemberAccessExpressionSyntax &&
                //   (node.Parent is ExpressionSyntax || node.Parent is MethodDeclarationSyntax || node.Parent is PropertyDeclarationSyntax
                // || node.Parent is BlockSyntax) &&
                !(node.Parent.Parent is InitializerExpressionSyntax) &&
              !(node.Parent is QualifiedNameSyntax) && !(node.Parent is MemberAccessExpressionSyntax) && !(node.Parent is ThisExpressionSyntax))
            {
                var nodeasMember = node as MemberAccessExpressionSyntax;
                if (!(nodeasMember.Expression is ThisExpressionSyntax))
                { 
                //Lets fully qualify these so that we can have property code working
                var symbolInfo = _semanticModel.GetSymbolInfo(node);

                    if (symbolInfo.Symbol != null &&
                        (symbolInfo.Symbol.Kind == SymbolKind.Field || symbolInfo.Symbol.Kind == SymbolKind.Property))
                    {
                        if (symbolInfo.Symbol.ContainingType != null && symbolInfo.Symbol.IsStatic)
                        {
                            var newName = symbolInfo.Symbol.ContainingType.GetFullNameCSharp() + "." +
                                          symbolInfo.Symbol.Name;
                            return SyntaxFactory.ParseExpression(newName);
                        }
                        else
                        {
                            ISymbol symbol = TypeProcessor.GetSymbolInfo((node as MemberAccessExpressionSyntax).Expression).Symbol;
                            if (
                                symbol != null && (!(symbol
                                    is
                                    ILocalSymbol) && !(symbol is IParameterSymbol) && symbol.Name != ".ctor"))
                            {
                                var firstParent =
                                    TypeProcessor.GetDeclaredSymbol(
                                        node.Ancestors().OfType<BaseTypeDeclarationSyntax>().First());
                                //_semanticModel.GetSymbolInfo(node.Ancestors().OfType<BaseTypeDeclarationSyntax>().First());
                                if (symbolInfo.Symbol.ContainingType != null && !symbolInfo.Symbol.IsStatic &&
                                    symbolInfo.Symbol.ContainingType == firstParent)
                                    return SyntaxFactory.ParseExpression("this." + node.ToFullString());
                            }

                        }
                    }
                    return base.Visit(node);
                }
            }

            return base.Visit(node);
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:97,代码来源:CSharpToDlangRewriter.cs

示例15: EvaluateImpl

		protected override EvaluationResult EvaluateImpl(SyntaxNode node)
		{
			var methodDeclaration = (MethodDeclarationSyntax)node;
			var returnStatements = methodDeclaration.DescendantNodes().Where(n => n.IsKind(SyntaxKind.ReturnStatement)).AsArray();
			if (returnStatements.Length > 1)
			{
				return new EvaluationResult
						   { 
							   Snippet = node.ToFullString(), 
							   ErrorCount = returnStatements.Length
						   };
			}

			return null;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:15,代码来源:MultipleReturnStatementsErrorRule.cs


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