Stuff in Reflection that's not in Metadata
Previously, I mentioned some things in Metadata that aren't exposed in Reflection. Here's an opposite case.
While metadata represents static bits on disk, Reflection operates in a live process with access to the CLR's loader. So reflection can represent things the CLR loader and type system may do that aren't captured in the metadata.
For example, an array T[] may implement interfaces, but which set of interfaces is not captured in the metadata. So consider the following code that prints out the interfaces an int[] implements:
using System; class Foo { static void Main() { Console.WriteLine("Hi"); Console.WriteLine(Environment.Version); Type[] t2 = typeof(int[]).GetInterfaces(); foreach (Type t in t2) { Console.WriteLine(t.FullName); } Console.WriteLine("done"); } }
Compile it once for v1.0. Then run the same binary against v1 and v2. It's the same file (and therefore same metadata) in both cases.
The V1 case is inconsistent because it doesn't show any interfaces, it should at least show a few builtins like IEnumerable (typeof(IEnumerable).IsAssignableFrom(typeof(int[])) == True). But in the v2 case, you see reflection showing the interfaces, particularly the new 2.0 generic interfaces, that the CLR's type system added to the the array. So the V2 list is not the same as the V1 list, but this difference is not captured in the metadata.
|