diff options
author | Nick Drochak <nickd@mono-cvs.ximian.com> | 2002-01-19 22:55:23 +0300 |
---|---|---|
committer | Nick Drochak <nickd@mono-cvs.ximian.com> | 2002-01-19 22:55:23 +0300 |
commit | b3a9502b960559d7a6b6c9712be8dd052b2e0e19 (patch) | |
tree | da34a2b334adf9a39aacdd9432552db1bdd39999 /mcs/nunit/src/NUnitCore/ReflectionUtils.cs | |
parent | aa634bb0419989a60379efba25e04e149936158e (diff) |
* Added sources and makefile for NUnit
svn path=/trunk/mcs/; revision=2066
Diffstat (limited to 'mcs/nunit/src/NUnitCore/ReflectionUtils.cs')
-rw-r--r-- | mcs/nunit/src/NUnitCore/ReflectionUtils.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/mcs/nunit/src/NUnitCore/ReflectionUtils.cs b/mcs/nunit/src/NUnitCore/ReflectionUtils.cs new file mode 100644 index 00000000000..19f656f04c4 --- /dev/null +++ b/mcs/nunit/src/NUnitCore/ReflectionUtils.cs @@ -0,0 +1,74 @@ +namespace NUnit.Runner {
+
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
+ using System.IO;
+ using System.Reflection;
+
+ using NUnit.Framework;
+/// <summary>
+///
+/// </summary>
+ public class ReflectionUtils{
+/// <summary>
+///
+/// </summary>
+/// <param name="testClass"></param>
+/// <returns></returns>
+ public static bool HasTests(Type testClass) {
+
+ PropertyInfo suiteProperty= null;
+ suiteProperty = testClass.GetProperty("Suite", new Type[0]);
+ if (suiteProperty == null ) {
+ // try to extract a test suite automatically
+ bool result = false;
+ TestSuite dummy = new TestSuite(testClass, ref result);
+ return result;
+ }
+ ITest test= null;
+ try {
+ // static property
+ test= (ITest)suiteProperty.GetValue(null, new Type[0]);
+ if (test == null)
+ return false;
+ } catch(Exception) {
+ return false;
+ }
+ return true;
+ }
+/// <summary>
+///
+/// </summary>
+/// <param name="assemblyName"></param>
+/// <returns></returns>
+ public static StringCollection GetAssemblyClasses(string assemblyName){
+ StringCollection classNames = new StringCollection ();
+ try {
+ Assembly testAssembly = Assembly.LoadFrom(assemblyName);
+
+ foreach(Type testType in testAssembly.GetExportedTypes()){
+ if(testType.IsClass && HasTests(testType)){
+ classNames.Add(testType.FullName);
+ }
+ }
+ }catch(ReflectionTypeLoadException rcle){
+
+ Type[] loadedTypes = rcle.Types;
+ Exception[] exceptions = rcle.LoaderExceptions;
+
+ int exceptionCount = 0;
+
+ for ( int i =0; i < loadedTypes.Length; i++ ){
+ Console.Error.WriteLine("Unable to load a type because {0}", exceptions[exceptionCount] );
+ exceptionCount++;
+ }
+ }catch(FileNotFoundException fnfe){
+ Console.Error.WriteLine(fnfe.Message);
+ }catch(Exception e){
+ Console.Error.WriteLine("Error reading file {0}: {1}", assemblyName, e.Message);
+ }
+ return classNames;
+ }
+ }
+}
|