Overview
PostSharp, unlike System.Reflection, is
module-centric. This means that all declarations have a meaning
only in the scope of a specific module. Declarations can be used
only in the module in which they are declared. When a module wants
to use an artifact (type, method, ...) defined in another module,
it has to use references.
PostSharp fortunately provides a facility to bind and translate declarations between modules.
Modules can be bound when they are part of a same Domain. A domain is precisely a scope in which modules and assemblies are bound.
Resolving references
Resolving a reference is the operation of getting the definition that is referred to by the reference.
Say you have a type TypeA defined in a module
ModuleA. This type is represented by a TypeDefDeclaration
in ModuleA. But if you want to use TypeA in
another module ModuleB, the same type will be represented
by a TypeRefDeclaration.
So resolving a TypeRefDeclaration means getting the
TypeDefDeclaration to which it relates.
Reference resolution is provided by the following methods:
IType.GetTypeDefinition(),
IField.GetFieldDefinition(),
IMethod.GetMethodDefinition()
and IAssembly.GetAssemblyEnvelope().
Translating declarations
Declarations are always only meaningful in the module in which they are declared. Translating a declaration is the operation of building another declaration that is meaningful in another module.
Take our previous example. Translating the
TypeDefDeclaration from ModuleA to
ModuleB would give a TypeRefDeclaration,
and translating the TypeRefDeclaration from
ModuleB to ModuleA would give a
TypeDefDeclaration.
Moving types
Wouldn't it be nice to have a facility to move type definitions from one module to another? Nice but not implemented...