Using TypeBuilder and System.Reflection.Emit to generate an assembly



Hi,



I have a compiled assembly: source.dll.

I would like to add a single method



public static string version(){

return "1.0.1.1";

}



to all the types in the assembly, maintaining type names, so the client code
wouldn't have to change.



I can traverse all the types in the assembly using:



Assembly a = Assembly.LoadFrom("source.dll");

Type[] mytypes = a.GetTypes();



Now I have info on all the types in the assembly.

And I can create my new type using



myAssemblyBuilder = myCurrentDomain.DefineDynamicAssembly(myAssemblyName,
AssemblyBuilderAccess.Save);

ModuleBuilder mBuilder =
myAssemblyBuilder.DefineDynamicModule("SourceModule","source.dll");

TypeBuilder builder = mBuilder.DefineType



But, I am not able to find the way to use modify source types.

I could inherit from source types, since DefineType method accepts BaseType
parameter but this does not resolve my problem, since I would like to
REPLACE original source.dll:



myAssemblyBuilder.Save("source.dll");



Help, please?



Thank you,



Dominic





.