0

In the program I am making a plugin for, multiple .dll files are loaded. One of these .dll/library/assemblies I am particularly interested in. This assembly contains a class with a method that returns a boolean. I want to be able to use Reflection.Emit to some how change what that method will return (maybe upon start up?). Some things to take note of:

  • I do not have access to the original source code of the .dll.
  • I do not want to use Plan B and decompile the referenced assembly with a Reflector, fixing the bugs, and recompiling.

The way everything works is that all of my code is currently compiled into a dll that is ran as a plugin for the real program. I really need to be able to override/rewrite method body/change the return value of an assembly that the program is using. The only thing I have heard is that Reflection.Emit may be my hope. It was simply a tip from someone that wants me to dive deeper.

Made up code of Assembly-called-from-program.dll:

public virtual bool exampleBool(bool b)
{
    return b;
}

Code I want to replace it with in My-plugin-for-program.dll:

public virtual bool exampleBool(bool b)
{
    return true;
}

This is just an example. I want to learn and adapt any provided tutorials and resources into what I want to actually accomplish. I didn't provide the actual code that I want to replace because it is too blocky.

user3150838
  • 61
  • 1
  • 5
  • You should have a look at this thread.. It will point you in a better direction. http://stackoverflow.com/questions/123540/modifying-existing-net-assemblies – Nico Jan 07 '14 at 05:48
  • Personally I've had better luck with Mono.Cecil for this sort of thing rather than Reflection.Emit. – J Trana Jan 07 '14 at 05:53
  • Thanks guys, I will look into it tomorrow. – user3150838 Jan 07 '14 at 06:09

0 Answers0