Using TypeBuilder and System.Reflection.Emit to generate an assembly
- From: "Dominic Souvoigne" <dsouvoigne@xxxxxxxxxxxxx>
- Date: Sat, 10 Sep 2005 15:11:35 -0400
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
.
- Prev by Date: Re: Period of System.Random
- Next by Date: Re: .NET SUCKS --- READ FOLLOWING. MICROSOFT IS A SUCKY CO
- Previous by thread: VS.NET (2.0), UserControl & Dispose
- Next by thread: Standy and Password prompt problem with .Net Framework
- Index(es):