What you *can* do is recursively look through the assemblies
referenced by your current assembly
Actually, one thing to note here is that the compiler is clever - it
will drop things that you have referenced but not used... just one to
watch if it doesn't work. You also need to watch for the circular
reference at the bottom ;-p
But something like below.
Marc
using System;
using System.Collections.Generic;
using System.Reflection;
static class Program
{
static void Main()
{
Type type = GetType("System.Xml.XmlReader");
}
static Type GetType(string name)
{
// tryu the lazy way first
Type type = Type.GetType(name);
if (type != null) return type;
List<stringskip = new List<string>();
AssemblyName root = Assembly.GetEntryAssembly().GetName();
return WalkAssemblies(name, root, skip);
}
static Type WalkAssemblies(string name, AssemblyName an,
IList<stringskip)
{
// check "an" for the type
skip.Add(an.FullName);
Assembly a;
try {
a = Assembly.Load(an);
} catch {
return null; // oops
}
Type type = a.GetType(name);
if (type != null) return type;
// see what is referenced
foreach(AssemblyName nextRef in a.GetReferencedAssemblies()) {
if(skip.Contains(nextRef.FullName)) continue;
type = WalkAssemblies(name, nextRef, skip);
if (type != null) return type;
}
return null;
}
}