00001 using System;
00002 using System.Collections;
00003 using System.Collections.Generic;
00004 using System.Text;
00005 using System.Reflection;
00006
00007 namespace DXGfxLib
00008 {
00009 public class ReflectionHelper
00010 {
00011 public static Hashtable ListCreatableClasses()
00012 {
00013 return ListCreatableClasses(typeof(ReflectionHelper).Assembly);
00014 }
00015
00016 public static Hashtable ListCreatableClasses(Assembly fromAssembly)
00017 {
00018 Hashtable hashTable = new Hashtable();
00019
00020 Type[] types = fromAssembly.GetTypes();
00021
00022 foreach (Type t in types)
00023 {
00024 if (t.IsClass && t.IsPublic)
00025 {
00026 hashTable.Add(t.FullName, t);
00027 }
00028 }
00029
00030 return hashTable;
00031 }
00032
00033 public static Object GetInstanceOfType(Type theType)
00034 {
00035 ConstructorInfo ctor = theType.GetConstructor(new Type[] { });
00036 Object[] args = new Object[] { };
00037 Object obj = ctor.Invoke(args);
00038 return obj;
00039 }
00040
00041 public static Object GetInstanceOfType(string typeName)
00042 {
00043 return GetInstanceOfType(typeof(ReflectionHelper).Assembly, typeName);
00044 }
00045
00046 public static Object GetInstanceOfType(Assembly sourceAssembly, string typeName)
00047 {
00048 Type theType = sourceAssembly.GetType(typeName);
00049
00050 if (theType == null)
00051 return null;
00052
00053 return GetInstanceOfType(theType);
00054 }
00055 }
00056 }