Modifying Existing .NET Assemblies

前端 未结 6 1195
醉酒成梦
醉酒成梦 2020-12-08 05:38

Is there a way to modify existing .NET assemblies without resorting to 3rd party tools? I know that PostSharp makes this possible but I find it incredibly wasteful that the

相关标签:
6条回答
  • 2020-12-08 06:13

    You can use MethodInfo.GetMethodBody().GetILAsByteArray(), modify that, and then plug it back into MethodBuilder.CreateMethodBody().

    0 讨论(0)
  • 2020-12-08 06:15

    Mono.Cecil also allows you to remove the strong name from a given assembly and save it back as an unsigned assembly. Once you remove the strong name from the assembly, you can just modify the IL of your target method and use the assembly as you would any other assembly. Here's the link for removing the strong name with Cecil:

    http://groups.google.com/group/mono-cecil/browse_thread/thread/3cc4ac0038c99380/b8ee62b03b56715d?lnk=gst&q=strong+named#b8ee62b03b56715d

    Once you've removed the strong name, you can pretty much do whatever you want with the assembly. Enjoy!

    0 讨论(0)
  • 2020-12-08 06:24

    .NET Framework assemblies are signed and just as Joel Coehoorn said you'll get a dud.

    0 讨论(0)
  • 2020-12-08 06:29

    One important point: if the assembly is signed, any changes will fail and you'll end up with a dud.

    0 讨论(0)
  • 2020-12-08 06:31

    You could load the assembly using IronRuby, and mixin all the functionality you can dream of

    0 讨论(0)
  • 2020-12-08 06:37

    It would help if you could provide a more specific use case, there are probably better ways to fix your problem than this.

    In .NET 3.5 it's possible to add extension methods to existing framework classes, perhaps that is enough?

    0 讨论(0)
提交回复
热议问题