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


C# IMethod.GetContainingType方法代码示例

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


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

示例1: Reset

 public void Reset(IMethod method, ITypeInfo typeInfo)
 {
     this.method = method;
     var containingType = method.GetContainingType();
     TypeName = containingType.GetClrName().FullName;
     Class = typeInfo ?? ((IClass) containingType).AsTypeInfo();
 }
开发者ID:EddieGarmon,项目名称:resharper-xunit,代码行数:7,代码来源:PsiMethodInfoAdapter.cs

示例2: IsUnitTestMethod

 private static bool IsUnitTestMethod(IMethod testMethod)
 {
     if (testMethod == null)
         return false;
     var containingType = testMethod.GetContainingType() as IClass;
     if (containingType == null)
         return false;
     return MethodUtility.IsTest(testMethod.AsMethodInfo(containingType.AsTypeInfo()));
 }
开发者ID:EddieGarmon,项目名称:resharper-xunit,代码行数:9,代码来源:PsiUnitTestIdentifier.cs

示例3: IsFromReactiveObservableClass

        public static bool IsFromReactiveObservableClass(IMethod method)
        {
            try
            {
                var classType = method.GetContainingType();
                if (classType == null)
                {
                    return false;
                }

                return classType.GetClrName().FullName == Constants.ReactiveLinqAssemblyFullName;
            }
            catch (Exception exn)
            {
                Debug.WriteLine(exn);
                return false;
            }
        }
开发者ID:oriches,项目名称:Resharper.ReactivePlugin,代码行数:18,代码来源:MethodHelper.cs

示例4: Wrap

        /// <summary>
        /// Obtains a reflection wrapper for a method.
        /// </summary>
        /// <param name="target">The method, or null if none.</param>
        /// <returns>The reflection wrapper, or null if none.</returns>
        public StaticMethodWrapper Wrap(IMethod target)
        {
            if (target == null)
                return null;

            StaticDeclaredTypeWrapper declaringType = MakeDeclaredTypeWithoutSubstitution(target.GetContainingType());
            return new StaticMethodWrapper(this, target, declaringType, declaringType, declaringType.Substitution);
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:13,代码来源:PsiReflectionPolicy6.cs

示例5: GetPrimaryDeclaredElementForMethod

    public static IDeclaredElement GetPrimaryDeclaredElementForMethod(IMethod declaredElement)
    {
      string methodName = declaredElement.ShortName;
      if ("parse".Equals(methodName.Substring(0, "parse".Length)))
      {
        string ruleName = methodName.Substring("parse".Length, methodName.Length - "parse".Length);
        var cache = declaredElement.GetPsiServices().Solution.GetComponent<PsiCache>();
        List<IPsiSymbol> symbols = cache.GetSymbols(PsiRenamesFactory.NameFromCamelCase(ruleName)).ToList();
        if (symbols.Count > 0)
        {
          IPsiSymbol symbol = symbols.ToArray()[0];
          ITreeNode element = symbol.SourceFile.GetPsiFile<PsiLanguage>(new DocumentRange(symbol.SourceFile.Document, 0)).FindNodeAt(new TreeTextRange(new TreeOffset(symbol.Offset), 1));
          List<PsiOptionSymbol> parserPackageName = cache.GetOptionSymbols("parserPackage").ToList();
          List<PsiOptionSymbol> parserClassName = cache.GetOptionSymbols("parserClassName").ToList();
          IList<IDeclaredElement> classes = new List<IDeclaredElement>();
          foreach (PsiOptionSymbol packageName in parserPackageName)
          {
            foreach (PsiOptionSymbol className in parserClassName)
            {
              if (packageName.SourceFile == className.SourceFile)
              {
                IPsiSourceFile sourceFile = packageName.SourceFile;
                CollectionUtil.AddRange(
                classes, sourceFile.PsiModule.GetPsiServices().CacheManager.GetDeclarationsCache(sourceFile.PsiModule, false, true).
                    GetTypeElementsByCLRName(packageName.Value + "." + className.Value));
              }
            }
          }

          var parentClass = declaredElement.GetContainingType() as IClass;
          if (parentClass != null)
          {
            if (classes.Contains(parentClass))
            {
              while (element != null)
              {
                if (element is IDeclaredElement)
                {
                  {
                    return (IDeclaredElement)element;
                  }
                }
                element = element.Parent;
              }
            }
          }
          {
            return null;
          }
        }
      }
      else
      {
        return GetPrimaryDeclaredElementForVisitorMethod(declaredElement, declaredElement);
      }
      return null;
    }
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:57,代码来源:DerivedDeclaredElementUtil.cs

示例6: GetPrimaryDeclaredElementForVisitorMethod

 private static IDeclaredElement GetPrimaryDeclaredElementForVisitorMethod(IDeclaredElement declaredElement, IMethod method)
 {
   var cache = declaredElement.GetPsiServices().Solution.GetComponent<PsiCache>();
   Dictionary<ITypeElement, IList<PsiOptionSymbol>> classesWithInfo = GetVisitorClasses(cache);
   if (classesWithInfo.Count > 0)
   {
     var parentClass = method.GetContainingType() as IClass;
     if (parentClass != null)
     {
       if (classesWithInfo.ContainsKey(parentClass))
       {
         IList<PsiOptionSymbol> list = classesWithInfo[parentClass];
         PsiOptionSymbol visitorName = list[0];
         PsiOptionSymbol methodSuffix = list[1];
         PsiOptionSymbol methodPrefix = list[2];
         IPsiSourceFile sourceFile = visitorName.SourceFile;
         string name = method.ShortName;
         if (name.Length > methodPrefix.Value.Length + methodSuffix.Value.Length)
         {
           if (methodPrefix.Value.Length > 0)
           {
             name = name.Substring(methodPrefix.Value.Length, name.Length - methodPrefix.Value.Length);
           }
           if (methodSuffix.Value.Length > 0)
           {
             name = name.Substring(0, name.Length - methodSuffix.Value.Length);
           }
           IEnumerable<IPsiSymbol> elements = cache.GetSymbols(NameFromCamelCase(name));
           foreach (IPsiSymbol psiSymbol in elements)
           {
             if (psiSymbol.SourceFile == sourceFile)
             {
               var psiFile = sourceFile.GetPsiFile<PsiLanguage>(new DocumentRange(psiSymbol.SourceFile.Document, 0)) as PsiFile;
               if (psiFile != null)
               {
                 IList<ISymbolInfo> infos = psiFile.FileRuleSymbolTable.GetSymbolInfos(name);
                 foreach (ISymbolInfo info in infos)
                 {
                   IDeclaredElement element = info.GetDeclaredElement();
                   if (element is RuleDeclaration)
                   {
                     var ruleDeclaration = element as RuleDeclaration;
                     {
                       return ruleDeclaration;
                     }
                   }
                 }
               }
             }
           }
         }
         else
         {
           {
             return null;
           }
         }
       }
     }
   }
   {
     return null;
   }
 }
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:64,代码来源:DerivedDeclaredElementUtil.cs

示例7: GenerateTestMethodBody

        /// <summary>
        /// Generates Arrange/Act/Assert stub for test method based on original method declaration
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="testMethod"></param>
        /// <param name="originalMethod"></param>
        /// <param name="psiModule"></param>
        private void GenerateTestMethodBody(CSharpElementFactory factory, IPsiModule psiModule, IMethodDeclaration testMethod, IMethod originalMethod)
        {
            ICSharpStatement anchorStatement = null;

              var paramsList = new StringBuilder();

              // Arrange
              foreach (var parameterDeclaration in originalMethod.Parameters)
              {
            var type = parameterDeclaration.Type;
            var stmt = factory.CreateStatement("$0 " + parameterDeclaration.ShortName + " = $1;", type, DefaultValueUtil.GetDefaultValue(type, testMethod.Language, psiModule));
            anchorStatement = testMethod.Body.AddStatementAfter(stmt, anchorStatement);

            if (paramsList.Length == 0) // First parameter
              ModificationUtil.AddChildBefore(anchorStatement, factory.CreateComment("// Arrange" + Environment.NewLine));
            else
              paramsList.Append(", ");
            paramsList.Append(parameterDeclaration.ShortName);
              }

              if (!originalMethod.ReturnType.IsVoid())
              {
            var stmt = factory.CreateStatement("$0 expected = $1;", originalMethod.ReturnType,
              DefaultValueUtil.GetDefaultValue(originalMethod.ReturnType, testMethod.Language, psiModule));
            anchorStatement = testMethod.Body.AddStatementAfter(stmt, anchorStatement);

            if (originalMethod.Parameters.IsEmpty())
              ModificationUtil.AddChildBefore(anchorStatement, factory.CreateComment("// Arrange"));
              }

              // Act
              var methodInvocation = (originalMethod.IsStatic ? "$1" : "my" + originalMethod.GetContainingType().ShortName + "Instance") + "." + originalMethod.ShortName;
              var invocationStatement = !originalMethod.ReturnType.IsVoid()
            ? factory.CreateStatement("$0 result = " + methodInvocation + "(" + paramsList + ");", originalMethod.ReturnType, originalMethod.GetContainingType())
            : factory.CreateStatement(methodInvocation + "(" + paramsList + ");", null, originalMethod.GetContainingType());
              anchorStatement = testMethod.Body.AddStatementAfter(invocationStatement, anchorStatement);

              AddCommentWithNewLineBefore(factory, anchorStatement, "// Act");

              // Assert
              if (!originalMethod.ReturnType.IsVoid())
              {
            var stmt = factory.CreateStatement("Assert.AreEqual(expected, result);");
            anchorStatement = testMethod.Body.AddStatementAfter(stmt, anchorStatement);

            AddCommentWithNewLineBefore(factory, anchorStatement, "// Assert");
              }
        }
开发者ID:flcdrg,项目名称:ReSharper-TestToolsPlugin,代码行数:55,代码来源:CreateTestsAction.cs

示例8: ProcessTestMethod

        private IUnitTestElement ProcessTestMethod(IMethod testMethod)
        {
            var project = psiFile.GetProject();
            var testClass = testMethod.GetContainingType() as IClass;

            if (!conventionCheck.IsValidTestMethod(project, testClass, testMethod))
                return null;

            var isDynamic = conventionCheck.IsParameterizedMethod(project, testClass, testMethod);

            var clrTypeName = testClass.GetClrName();
            var assemblyPath = project.GetOutputFilePath().FullPath;
            return unitTestElementFactory.GetOrCreateTestMethod(project, clrTypeName, testMethod.ShortName, assemblyPath, isDynamic);
        }
开发者ID:TylerCarlson1,项目名称:ReSharperFixieRunner,代码行数:14,代码来源:PsiFileExplorer.8.1.cs

示例9: ProcessTestMethod

        private IUnitTestElement ProcessTestMethod(IMethod method)
        {
            var type = method.GetContainingType();
            var @class = type as IClass;
            if (type == null || @class == null || !IsValidTestClass(@class))
                return null;

            var command = TestClassCommandFactory.Make(@class.AsTypeInfo());
            if (command == null)
                return null;

            var fixtureElementClass = classes[type];
            if (fixtureElementClass == null)
                return null;

            if (command.IsTestMethod(method.AsMethodInfo()))
            {
                return provider.GetOrCreateMethodElement(type.GetClrName().FullName + "." + method.ShortName, project, (XunitTestClassElement) fixtureElementClass, envoy);
            }

            return null;
        }
开发者ID:Eskat0n,项目名称:ReSharper.XUnitTestRunner,代码行数:22,代码来源:XunitFileExplorer.cs

示例10: ProcessTestMethod

        private IUnitTestElement ProcessTestMethod(IMethod method, out IList<IUnitTestElement> rowTests)
        {
            rowTests = null;
            var @class = method.GetContainingType() as IClass;
            bool isAbstract;
            if (@class == null || !IsValidTestClass(@class, out isAbstract))
                return null;

            var elements = classes[@class];
            if (elements.Count == 1 && !isAbstract)
            {
                var classElement = elements.First();
                if (classElement == null)
                    return null;

                if (UnitTestElementPsiIdentifier.IsUnitTest(method))
                    return factory.GetOrCreateMethodElement(@class.GetClrName(), method.ShortName, project, classElement, envoy, UnitTestElementPsiIdentifier.GetSkipReason(method));

                return null;
            }
            if (elements.Count == 0)
                return null;

            rowTests = elements.Select(classElement => GetOrCreateMethodElement(classElement, @class, method))
                .Cast<IUnitTestElement>()
                .ToList();

            return factory.CreateFakeElement(project, @class.GetClrName(), method.ShortName);
        }
开发者ID:hazzik,项目名称:ReSharper.XUnitTestRunner,代码行数:29,代码来源:XunitFileExplorer.cs


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