Since there can be time when it is important to only load the metainformation -based on performance, for example-, ReflectionOnly methods help that.
Probably we will include this in Mono in the next weeks, as long as I finish the methods -currently I have a working Assembly.ReflectionOnlyLoadFrom method- and let them to be reviewed by the jit guys.
Below an example:
using System;
using System.Reflection;
public class Tester {
static void Main ()
{
Assembly ass1, ass2;
AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;
ass1 = Assembly.ReflectionOnlyLoadFrom ("AssemblyRefParent.dll");
ass2 = Assembly.ReflectionOnlyLoadFrom ("AssemblyRefChild.dll");
Type t = ass2.GetType ("Child");
if (t == null) {
Console.WriteLine ("Type Child could not be loaded");
return;
}
Console.WriteLine ("Parent of Child = {0}", t.BaseType.Name);
Console.WriteLine ("ReflectionOnly Assemblies:");
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
Console.WriteLine ("\t{0}, ReflectionOnly = {1}", a.FullName, a.ReflectionOnly);
}
}
static void OnAssemblyLoad (object o, AssemblyLoadEventArgs args)
{
Assembly loaded = args.LoadedAssembly;
Console.WriteLine ("Assembly Loaded = {0}", loaded.FullName);
Console.WriteLine ("Is Reflection Only = {0}\n", loaded.ReflectionOnly);
}
}
Output
Assembly Loaded = AssemblyRefParent, Culture=neutral
Is Reflection Only = True
Assembly Loaded = AssemblyRefChild, Culture=neutral
Is Reflection Only = True
Parent of Child = Parent
ReflectionOnly Assemblies:
AssemblyRefDriver, Culture=neutral, ReflectionOnly = False
mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, ReflectionOnly = False
AssemblyRefChild, Culture=neutral, ReflectionOnly = True
AssemblyRefParent, Culture=neutral, ReflectionOnly = True
5 comentarios:
Publicar un comentario