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


C# SemanticModel.AnalyzeDataFlow方法代码示例

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


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

示例1: AreVariablesOnlyWrittenInsideDeclaration

 static bool AreVariablesOnlyWrittenInsideDeclaration(LocalDeclarationStatementSyntax declaration, SemanticModel semanticModel)
 {
     var dfa = semanticModel.AnalyzeDataFlow(declaration);
     var symbols = from variable in declaration.Declaration.Variables
                   select semanticModel.GetDeclaredSymbol(variable);
     var result = !symbols.Any(s => dfa.WrittenOutside.Contains(s));
     return result;
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:8,代码来源:MakeLocalVariableConstWhenItIsPossibleAnalyzer.cs

示例2: MethodShouldBeStatic

		private static bool MethodShouldBeStatic(MethodDeclarationSyntax method, SemanticModel semanticModel)
		{
			if (method.Body == null) return false;

			var dataFlow = semanticModel.AnalyzeDataFlow(method.Body);
			var variablesDeclared = dataFlow.VariablesDeclared.ToList();
			var variablesRead = dataFlow.ReadInside.Union(dataFlow.ReadOutside).ToList();
			if (variablesDeclared.Any(c => c.Name == "this"))
			{
				return false;
			}
			if (variablesRead.Any(c => c.Name == "this"))
			{
				return false;
			}
			return true;
开发者ID:mmahulea,项目名称:FactonExtensionPackage,代码行数:16,代码来源:MakeStaticMethodsCommand.cs

示例3: GetCapturedVariables

 protected override ImmutableArray<ISymbol> GetCapturedVariables(SemanticModel model, SyntaxNode memberBody)
 {
     Debug.Assert(memberBody.IsKind(SyntaxKind.Block) || memberBody is ExpressionSyntax);
     return model.AnalyzeDataFlow(memberBody).Captured;
 }
开发者ID:GeertVL,项目名称:roslyn,代码行数:5,代码来源:CSharpEditAndContinueAnalyzer.cs

示例4: UsedOutsideParentBlock

 private static bool UsedOutsideParentBlock(SemanticModel semanticModel, StatementSyntax expressionStatement, ISymbol identitySymbol)
 {
     var block = expressionStatement.FirstAncestorOrSelf<BlockSyntax>();
     var method = expressionStatement.FirstAncestorOrSelf<MethodDeclarationSyntax>();
     var methodBlock = method.Body;
     if (methodBlock.Equals(block)) return false;
     var collectionOfStatementsAfter = GetStatementsInBlocksAfter(block);
     foreach (var allStatementsAfterBlock in collectionOfStatementsAfter)
     {
         if (!allStatementsAfterBlock.Any()) continue;
         var dataFlowAnalysis = semanticModel.AnalyzeDataFlow(allStatementsAfterBlock.First(), allStatementsAfterBlock.Last());
         if (!dataFlowAnalysis.Succeeded) continue;
         var isUsed = dataFlowAnalysis.ReadInside.Contains(identitySymbol)
             || dataFlowAnalysis.WrittenInside.Contains(identitySymbol);
         if (isUsed) return true;
     }
     return false;
 }
开发者ID:Cadums01,项目名称:code-cracker,代码行数:18,代码来源:DisposableVariableNotDisposedCodeFixProvider.cs

示例5: GetReadSymbolsCondition

        private static IEnumerable<ISymbol> GetReadSymbolsCondition(ForStatementSyntax forNode,
            SemanticModel semanticModel)
        {
            if (forNode.Condition == null)
            {
                return new ISymbol[0];
            }

            var dataFlowAnalysis = semanticModel.AnalyzeDataFlow(forNode.Condition);

            return dataFlowAnalysis.Succeeded
                ? dataFlowAnalysis.ReadInside.Distinct()
                : new ISymbol[0];
        }
开发者ID:roel4ez,项目名称:sonarlint-vs,代码行数:14,代码来源:ForLoopCounterCondition.cs

示例6: CanBeMadeConst

        private static bool CanBeMadeConst(LocalDeclarationStatementSyntax localDeclaration, SemanticModel semanticModel)
        {
            // already const?
            if (localDeclaration.Modifiers.Any(SyntaxKind.ConstKeyword))
            {
                return false;
            }

            // Ensure that all variables in the local declaration have initializers that
            // are assigned with constant values.
            foreach (var variable in localDeclaration.Declaration.Variables)
            {
                var initializer = variable.Initializer;
                if (initializer == null)
                {
                    return false;
                }

                var constantValue = semanticModel.GetConstantValue(initializer.Value);
                if (!constantValue.HasValue)
                {
                    return false;
                }

                var variableTypeName = localDeclaration.Declaration.Type;
                var variableType = semanticModel.GetTypeInfo(variableTypeName).ConvertedType;

                // Ensure that the initializer value can be converted to the type of the
                // local declaration without a user-defined conversion.
                var conversion = semanticModel.ClassifyConversion(initializer.Value, variableType);
                if (!conversion.Exists || conversion.IsUserDefined)
                {
                    return false;
                }

                // Special cases:
                //   * If the constant value is a string, the type of the local declaration
                //     must be System.String.
                //   * If the constant value is null, the type of the local declaration must
                //     be a reference type.
                if (constantValue.Value is string)
                {
                    if (variableType.SpecialType != SpecialType.System_String)
                    {
                        return false;
                    }
                }
                else if (variableType.IsReferenceType && constantValue.Value != null)
                {
                    return false;
                }
            }

            // Perform data flow analysis on the local declaration.
            var dataFlowAnalysis = semanticModel.AnalyzeDataFlow(localDeclaration);

            // Retrieve the local symbol for each variable in the local declaration
            // and ensure that it is not written outside of the data flow analysis region.
            foreach (var variable in localDeclaration.Declaration.Variables)
            {
                var variableSymbol = semanticModel.GetDeclaredSymbol(variable);
                if (dataFlowAnalysis.WrittenOutside.Contains(variableSymbol))
                {
                    return false;
                }
            }

            return true;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:69,代码来源:DiagnosticAnalyzer.cs

示例7: ContainsLocalReferences

 static bool ContainsLocalReferences(SemanticModel context, SyntaxNode expr, SyntaxNode body)
 {
     var dataFlowAnalysis = context.AnalyzeDataFlow(expr);
     return dataFlowAnalysis.Captured.Any();
 }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:5,代码来源:ExtractAnonymousMethodCodeRefactoringProvider.cs


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