mono.cecil

Preprocessing C# - Detecting Methods

Hey, I require the ability to preprocess a number of C# files as a prebuild step for a project, detect the start of methods, and insert generated code at the start of the method, before any existing code. I am, however, having a problem detecting the opening of a method. I initially tried a regular expression to match, but ended up wi...

Detect whether the assembly was built for .NET Compact Framework

Having a .NET assembly, how can I detect whether it was built for .NET CF or a full framework? ...

Detect Silverlight version required by an assembly

How can I tell whether Silverlight 2 is sufficient for an assembly or Silverlight 3 is required? I have all information that is available through reflection (Mono.Cecil). Same question for SL 3 versus 4. Thanks in advance. ...

How do I find all the type dependecies of a given type in any CLR based language assembly?

I am trying to find all the types that a given type is dependent on, including interfaces, abstract classes, enums, structs, etc. I want to load up an assembly, and print out a list of all the types defined within it, and their dependencies. So far I have been able to find all the the external types a CLR assembly depends on using Mono....

Create getter property with backing field using Mono.Cecil

I'm trying to inject getter property into already compiled assembly. Without backing field, it's reasonably easy: AssemblyDefinition targetasmdef = AssemblyFactory.GetAssembly(@"E:\tmp\sandbox\Cecil\ConsoleApplication1\library\bin\Debug\library.dll"); TypeReference returnTypeRef = targetasmdef.MainModule.Import(typeof(string)); MethodD...

Replacing a class with Mono.Cecil

Say I have assembly A. It was modified with Mono.Cecil a little bit. Now say I have assembly B. It has a class named SomeClass. Assembly A also has a class named SomeClass. Now I want to replace SomeClass from assembly A with the one in assembly B. I tried a few things, but I know that for one of my attempts, it actually remapped a metho...

Can Mono.Cecil modify code already loaded in the AppDomain?

I want to add some behavior to a certain class at runtime. I know how to subclass at runtime using Reflection.Emit but thats not enough, Depending on some external configuration I need to inject opcodes in a method on a type T so all classes that inherit from it automatically gain this behavior.(I cant use the .NET Profiling API) Can s...

How to alias an interface method implementation with Mono.Cecil?

I'm using Mono.Cecil (version 0.6.9.0) to alias a method that implements an interface method. To do that, I have to add an Override to the target method that points back to the interface method (much like what's possible with VB.NET), like this: using System; using System.Reflection; using Mono.Cecil; class Program { static void Mai...