Reflection.Emit vs Mono.Cecil, which is best suited?

I’ve been looking into the modification of assemblies for game development purposes and i’ve found that Reflection.Emit and Mono.Cecil are both able to perform this task, but i’m not sure which would be best.

The articles i’ve found are several years old, so i don’t have any up-to-date information. When it comes to generating methods and modifying method calls, which would be best for this task?

A specific example for usage would be sending a message from server to client (or vice versa) in a manner similar to Unity’s Commands and RPC calls:

Unity rewrites this call so that the server will send a message to all clients that contains any parameters that were passed in. The client then invokes the method locally. As i understand it this modification process occurs after compilation on the assembly file itself, meaning when run the assembly already contains the modifications.

I don’t have any experience with either of these, so i don’t know what their capabilities are. The examples i found for Reflection.Emit only mention creating new types, not modifying existing ones which Mono.Cecil does seem to be able to do.

submitted by /u/Solokiller
[link] [comments]

Leave a Reply