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


C# MethodDeclarationSyntax.ToLog方法代码示例

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


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

示例1: DetectBlockingAsyncCallers

		public void DetectBlockingAsyncCallers(MethodDeclarationSyntax node)
		{
			var symbol = SemanticModel.GetDeclaredSymbol(node);
			if (symbol != null)
			{
				foreach (var refs in SymbolFinder.FindReferencesAsync(symbol, SourceFile.Project.Solution).Result)
				{
					foreach (var loc in refs.Locations)
					{
						var textSpan = loc.Location.SourceSpan;
						var callerNode = loc.Document.GetSyntaxRootAsync().Result.DescendantNodes(textSpan).FirstOrDefault(n => textSpan.Contains(n.Span));
						var callerText = loc.Document.GetTextAsync().Result.Lines.ElementAt(loc.Location.GetLineSpan().StartLinePosition.Line).ToString();
						if (callerText.Contains(".Wait()")) // caller.Contains(".Result")
						{
							Logs.TempLog5.Info("Blocking Caller Name: " + callerText.Trim() + " from this file: " + loc.Document.FilePath);
							var temp = callerNode != null ? callerNode.Ancestors().OfType<MethodDeclarationSyntax>().FirstOrDefault() : null;
							if (temp != null)
							{
								Logs.TempLog5.Info("Blocking Caller Method Node: " + temp.ToLog());
								if (temp.IsAsync())
								{
									Logs.TempLog5.Info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
								}
							}

							Logs.TempLog5.Info("Async method Callee from this file " + SourceFile.FilePath + node.ToLog()+ Logs.Break);
						}
					}
				}
			}
		}
开发者ID:modulexcite,项目名称:CSharpAnalyzer,代码行数:31,代码来源:AsyncAwaitAntiPatternsWalker.cs

示例2: VisitMethodDeclaration

        public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
        {
            if (!node.HasAsyncModifier())
            {
                base.VisitMethodDeclaration(node);
                return;
            }

            if (node.ToString().Contains("await"))
            {
                Result.asyncAwaitResults.NumAsyncMethods++;

                Logs.TempLog.Info(@"{0}{1}**********************************************", Document.FilePath, node.ToLog());

                if (!node.ReturnType.ToString().Equals("void"))
                {
                    Result.asyncAwaitResults.NumAsyncTaskMethods++;
                }

                if (IsFireForget(node))
                    Result.StoreDetectedAsyncMisuse(1, Document, node);

                if (IsUnnecessaryAsyncAwait(node))
                    Result.StoreDetectedAsyncMisuse(2, Document, node);

                if (IsThereLongRunning(node))
                    Result.StoreDetectedAsyncMisuse(3, Document, node);

                if (IsUnnecessarilyCaptureContext(node, 0))
                    Result.StoreDetectedAsyncMisuse(4, Document, node);


                //var symbol = SemanticModel.GetDeclaredSymbol(node);
                //if (symbol != null)
                //{

                //    foreach (var refs in SymbolFinder.FindReferencesAsync(symbol, Document.Project.Solution).Result)
                //    {
                //        foreach (var loc in refs.Locations)
                //        {
                //            var caller = loc.Document.GetTextAsync().Result.Lines.ElementAt(loc.Location.GetLineSpan().StartLinePosition.Line).ToString();
                //            if (caller.Contains(".Result") || caller.Contains(".Wait"))
                //                Logs.TempLog5.Info("{0}{1}{2}{3}************************************",
                //                    System.Environment.NewLine + "Blocking Caller: '" + caller.Trim() + "' from this file: " + loc.Document.FilePath + System.Environment.NewLine,
                //                    System.Environment.NewLine + "Async method Callee: " + System.Environment.NewLine,
                //                    node.ToLog(),
                //                    "From this file: " + Document.FilePath + System.Environment.NewLine + System.Environment.NewLine);
                //        }
                //    }
                //}
            }
            else
                Logs.AsyncMisuse.Info(@"{0} - {1}{2}**********************************************", Document.FilePath, "No Await", node.ToLog());

            base.VisitMethodDeclaration(node);
        }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:56,代码来源:AsyncAwaitDetectionWalker.cs

示例3: StoreDetectedAsyncMisuse

 internal void StoreDetectedAsyncMisuse(int type, Microsoft.CodeAnalysis.Document Document, MethodDeclarationSyntax node)
 {
     string name="";
     switch(type)
     {
         case 1:
             name = "fireforget";
             asyncAwaitResults.NumFireForget++;
             break;
         case 2:
             name = "unnecessaryasync";
             asyncAwaitResults.NumUnnecessaryAsync++;
             break;
         case 3:
             name = "longrunning";
             asyncAwaitResults.NumLongRunning++;
             break;
         case 4:
             name = "unnecessarycontext";
             asyncAwaitResults.NumUnnecessaryContext++;
             break;
     }
     Logs.AsyncMisuse.Info(@"{0} - {1}{2}**********************************************", Document.FilePath, name, node.ToLog());
 }
开发者ID:modulexcite,项目名称:concurrent-code-analyses,代码行数:24,代码来源:ConsultingAnalysisResult.cs


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