Versioning problems 2
(Sorry - I prematurely sent an empty message with the same subject a few
moments ago)
Hi there,
This is a follow-up to a posting I submitted earlier today but it probably
warrants a new thread. I'm having the following problem. I need to convert
the following compile-time code to its late-bound equivalent using
reflection (lines 3 through 6 only - the purpose being that I don't want to
be bound to the compile-time version of the DLL containing the "VCCodeModel"
interface - see this below)). Note that it's stripped down for brevity:
1) using Microsoft.VisualStudio.VCCodeModel; // Namespace containing the
"VCCodeBase" interface
2) EnvDTE80.CodeElement2 baseClass = GetThisFromSomewhere(); // Note that
"CodeElement2" is also an interface
3) VCCodeBase codeBase = baseClass as VCCodeBase;
4) if (codeBase != null)
5) {
6) EnvDTE80.CodeClass2 baseClass = codeBase.Class as CodeClass2;
7) }
So how do I re-write this using reflection (again, lines 3 through 6 only).
My first problem is that if I replace lines 3 and 4 above with this instead
....
if (typeof(VCCodeBase).IsAssignableFrom(baseClass))
.... then shouldn't it return true assuming line 4 above also returns true
(in the early-bound version)? It actually returns false however (i.e., when
line 4 above is true in the early-bound version, the call to
"IsAssignableFrom()" returns false). I'm not even sure if "typeof" is still
bound to the compile-term version of "VCCodeBase" but I can see why this is
probably happening though (since "baseClass" doesn't actually implement
"VCCodeBase" but the object "baseClass" is currently attached to does). What
other technique should I therefore be relying on to get the "reflection"
equivalent of lines 3 to 6? Thanks in advance.