Hopefully I'm not being too annoying here with all these questions... :)
Is there a relatively straightforward way to map between CCI and Reflection models of an assembly?
More specifically, one of the things that I'm trying to do at the moment is to walk through an assembly (which I don't want to load via Reflection, and may end up mutating later on) and discover instances of a particular set of custom attributes, defined
in another assembly. That second assembly is being loaded into both CCI and the host app (so is accessible via reflection).
I've got code which can find the elements that have the attributes applied to them (although the lookup is a bit messy; it uses UnitHelper.AssembliesAreEquivalent and TypeHelper.GetDefiningUnitReference to ask "is this attribute defined in the attribute
assembly?"). That much seems to be working fine.
What I'd really like though is some way to take the ICustomAttribute and produce an actual concrete instance of the attribute (ie. invoke the constructor and provide it with the equivalent parameters from the metadata). Given that the "real"
assembly is already loaded, it seems like it ought to be possible. I'm hoping that there's an easier/better way than looking up each element individually by name with the reflection APIs, though.
(I want to get a "real" attribute because I can query its properties much easier that way.)
And on a related note, given a MetadataReaderHost with the required assemblies loaded into it, and a Type, is there a quick way to get to the corresponding ITypeDefinition? I've found this:
UnitHelper.FindType(host.NameTable, host.FindAssembly(UnitHelper.GetAssemblyIdentity(type.Assembly.GetName(), host)), type.FullName)
which looks like it ought to work (though I haven't tried it yet). Seems a bit long-winded though (but I guess I could always just create my own helper functions to shorten it). Is there a better way?