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


C# IAssemblyInfo.GetType方法代码示例

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


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

示例1: ParseTestCaseName

        /// <summary>
        /// Parses a code element from an NUnit test case name.
        /// The name generally consists of the fixture type full-name followed by
        /// a dot and the test method name.
        /// </summary>
        private static ICodeElementInfo ParseTestCaseName(IAssemblyInfo assembly, string name)
        {
            if (assembly != null)
            {
                // Handle row-test naming scheme.
                int firstParen = name.IndexOf('(');
                if (firstParen >= 0)
                    name = name.Substring(0, firstParen);

                // Parse the identifier.
                if (IsProbableIdentifier(name))
                {
                    int lastDot = name.LastIndexOf('.');
                    if (lastDot > 0 && lastDot < name.Length - 1)
                    {
                        string typeName = name.Substring(0, lastDot);
                        string methodName = name.Substring(lastDot + 1);

                        ITypeInfo type = assembly.GetType(typeName);
                        if (type != null)
                        {
                            try
                            {
                                return type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
                            }
                            catch (AmbiguousMatchException)
                            {
                                // We may have insufficient information to distinguish overloaded
                                // test methods.  In this case we give up trying to find the code element.
                            }
                        }
                    }
                }
            }

            return null;
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:42,代码来源:NUnitTestExplorerEngine.cs

示例2: ParseTestFixtureName

        /// <summary>
        /// Parses a code reference from an NUnit test fixture name.
        /// The name generally consists of the fixture type full-name.
        /// </summary>
        private static ICodeElementInfo ParseTestFixtureName(IAssemblyInfo assembly, string name)
        {
            if (assembly != null)
            {
                if (IsProbableIdentifier(name))
                {
                    return assembly.GetType(name);
                }
            }

            return null;
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:16,代码来源:NUnitTestExplorerEngine.cs

示例3: BuildAssemblyTest_Native

        private Test BuildAssemblyTest_Native(IAssemblyInfo assembly, string location)
        {
            if (String.IsNullOrEmpty(location))
                throw new ArgumentNullException("location");

            // If csUnit.Core is not in the GAC then it must be in the assembly path due to a
            // bug in csUnit setting up the AppDomain.  It sets the AppDomain's base directory
            // to the assembly directory and sets its PrivateBinPath to the csUnit directory
            // which is incorrect (PrivateBinPath only specifies directories relative to the app base)
            // so it does actually not ensure that csUnit.Core can be loaded as desired.
            Assembly csUnitCoreAssembly = typeof(csUnit.Core.Loader).Assembly;
            if (!csUnitCoreAssembly.GlobalAssemblyCache)
            {
                string csUnitAppBase = Path.GetDirectoryName(location);
                string csUnitCoreAssemblyPathExpected = Path.Combine(csUnitAppBase, "csUnit.Core.dll");
                if (!File.Exists(csUnitCoreAssemblyPathExpected))
                {
                    return CreateAssemblyTest(assembly, location, delegate(Test assemblyTest)
                    {
                        TestModel.AddAnnotation(new Annotation(AnnotationType.Error, null,
                            string.Format("Cannot load csUnit tests from '{0}'.  "
                            + "'csUnit.Core.dll' and related DLLs must either be copied to the same directory as the test assembly or must be installed in the GAC.",
                            location)));
                    });
                }
            }

            // Load the assembly using the native CSUnit loader.
            using (Loader loader = new Loader(location))
            {
                // Construct the test tree
                return CreateAssemblyTest(assembly, location, delegate(Test assemblyTest)
                {
                    TestFixtureInfoCollection collection = loader.TestFixtureInfos;
                    if (collection == null)
                        return;

                    foreach (ITestFixtureInfo fixtureInfo in collection)
                    {
                        try
                        {
                            ITypeInfo fixtureType = assembly.GetType(fixtureInfo.FullName);

                            assemblyTest.AddChild(CreateFixtureFromType(fixtureType, delegate(Test fixtureTest)
                            {
                                if (fixtureInfo.TestMethods == null)
                                    return;

                                foreach (ITestMethodInfo testMethodInfo in fixtureInfo.TestMethods)
                                {
                                    try
                                    {
                                        IMethodInfo methodType = fixtureType.GetMethod(testMethodInfo.Name,
                                            BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);

                                        fixtureTest.AddChild(CreateTestFromMethod(methodType, null));
                                    }
                                    catch (Exception ex)
                                    {
                                        TestModel.AddAnnotation(new Annotation(AnnotationType.Error, fixtureType,
                                            "An exception was thrown while exploring a csUnit test case.", ex));
                                    }
                                }
                            }));
                        }
                        catch (Exception ex)
                        {
                            TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly,
                                "An exception was thrown while exploring a csUnit test fixture.", ex));
                        }
                    }
                });
            }
        }
开发者ID:dougrathbone,项目名称:mbunit-v3,代码行数:74,代码来源:CSUnitTestExplorer.cs


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