Question on Reflection

A

avnrao

I have a requirement in C# using Reflection..but I am not sure if that is
possible. If possible, please guide me on how to proceed on it.

Requirement is : I have a dll named x.dll. I would like to programmatically
add some piece of code to all of the methods in that dll, and save it. I
have created assemblies on the fly, but never found a way to modify an
existing assembly.

System.CodeDom provides a way to create assemblies and everything newly..
but how do i use CodeDom for the existing assemblies. Existing meaning, I
want to open an assembly, find out a method and add some code to the
method..programmatically.

pls help..
 
S

Saradhi

Thats an interesting question.
To answer it, you need to ask yourself a question, "WHY DO I NEED TO MODIFY THE CONETENTS OF AN EXISTINING ASSEMBLY"???

-SARADHI
I have a requirement in C# using Reflection..but I am not sure if that is
possible. If possible, please guide me on how to proceed on it.

Requirement is : I have a dll named x.dll. I would like to programmatically
add some piece of code to all of the methods in that dll, and save it. I
have created assemblies on the fly, but never found a way to modify an
existing assembly.

System.CodeDom provides a way to create assemblies and everything newly..
but how do i use CodeDom for the existing assemblies. Existing meaning, I
want to open an assembly, find out a method and add some code to the
method..programmatically.

pls help..
 
R

Richard Blewett [DevelopMentor]

Hi,

Are you looking to layer in code as in aspect orientate programming? The only way to do this is to the the classes whose methods you want to adorn derive from ContextBoundObject. In the general case there is no way to do what you want to do.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

I have a requirement in C# using Reflection..but I am not sure if that is
possible. If possible, please guide me on how to proceed on it.

Requirement is : I have a dll named x.dll. I would like to programmatically
add some piece of code to all of the methods in that dll, and save it. I
have created assemblies on the fly, but never found a way to modify an
existing assembly.

System.CodeDom provides a way to create assemblies and everything newly..
but how do i use CodeDom for the existing assemblies. Existing meaning, I
want to open an assembly, find out a method and add some code to the
method..programmatically.

pls help..
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi avarao,

The answer is NO. It is not possible. Assemblies are compiled units and as
such they cannot be chanaged.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top