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


C# ITreeNode.GetProject方法代码示例

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


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

示例1: GetNullReferenceState

    /// <summary>
    /// Gets the state of the expression null reference.
    /// </summary>
    /// <param name="treeNode">The element.</param>
    /// <param name="declaredElement">The declared element.</param>
    /// <param name="statement">The statement.</param>
    /// <returns>Returns the expression null reference state.</returns>
    private CodeAnnotationAttribute GetNullReferenceState(ITreeNode treeNode, IDeclaredElement declaredElement, IDeclarationStatement statement)
    {
      var project = treeNode.GetProject();
      if (project == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var projectFile = project.ProjectFile;
      if (projectFile == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var functionDeclaration = treeNode.GetContainingNode<ICSharpFunctionDeclaration>(true);
      if (functionDeclaration == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var builder = new CSharpControlFlowBuilder();
      var graf = builder.GraphFromNode(functionDeclaration, null, true) as ICSharpControlFlowGraph;
      if (graf == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var inspect = graf.Inspect(ValueAnalysisMode.OPTIMISTIC);

      var position = this.FindPosition(graf.BodyElement.Children, statement);
      if (position == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      position = this.FindFollowing(position);
      if (position == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var result = inspect.GetVariableStateAt(position, declaredElement);
      switch (result)
      {
        case CSharpControlFlowNullReferenceState.NOT_NULL:
          return CodeAnnotationAttribute.NotNull;

        case CSharpControlFlowNullReferenceState.NULL:
          return CodeAnnotationAttribute.CanBeNull;

        case CSharpControlFlowNullReferenceState.MAY_BE_NULL:
          return CodeAnnotationAttribute.CanBeNull;
      }

      return CodeAnnotationAttribute.Undefined;

      /*
      var block = treeNode.GetContainingNode<IBlock>(true);
      if (block == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var project = treeNode.GetProject();
      if (project == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var projectFile = project.ProjectFile;
      if (projectFile == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var factory = CSharpElementFactory.GetInstance(treeNode.GetPsiModule());
      var statement = factory.CreateStatement("if(" + name + " == null) { }");

      var ifStatement = block.AddStatementAfter(statement, (ICSharpStatement)anchorStatement) as IIfStatement;
      if (ifStatement == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var equalityExpression = ifStatement.Condition as IEqualityExpression;
      if (equalityExpression == null)
      {
        return CodeAnnotationAttribute.Undefined;
      }

      var referenceExpression = equalityExpression.LeftOperand as IReferenceExpression;
      if (referenceExpression == null)
      {
//.........这里部分代码省略.........
开发者ID:JakobChristensen,项目名称:Resharper.CodeAnnotations,代码行数:101,代码来源:CodeAnnotation.cs


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