Questions tagged [mono.cecil]

Mono.Cecil is a library to generate and inspect programs and libraries in the ECMA CIL form.

Mono.Cecil is a cross platform library, working equally well on .net and Mono, used to analyze, modify and write .net assemblies.

It is used in a variety of open source projects and commercial products.

Links

390 questions
10
votes
4 answers

Mono.Cecil type.IsAssignableFrom(derivedType) equivalent

I'm using Mono.Cecil to find types in Assembly that are derived from given on. Normaly it can be done with IsAssignableFrom() method, but I cannot fing it's equivalent in Cecil. Is there any such method or other way to check it? Thanks Mike
stachu
  • 277
  • 1
  • 3
  • 13
10
votes
2 answers

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 that's not enough. Depending on some external configuration I need to inject opcodes in a method on a type T so all classes that…
Thiago Padilha
  • 4,590
  • 5
  • 44
  • 69
10
votes
1 answer

Emit call to System.Lazy constructor with Mono.Cecil

I'm trying to emit a method that instantiates a System.Lazy and failing with a PEVerify error of "Invalid token", at the line newobj instance void class [mscorlib]System.Lazy`1::.ctor(class…
Ben
  • 6,023
  • 1
  • 25
  • 40
8
votes
2 answers

Visual Studio Watch window not taking into account usings

I have the following code in a view model: public Point Location { get { var rangePixels = Range * PixelsPerMile; var xCoordinate = OwnLocation.X * MapScale + rangePixels * Math.Cos(Theta); var yCoordinate =…
devuxer
  • 41,681
  • 47
  • 180
  • 292
8
votes
2 answers

cecil: Instruction.Operand types corresponding to Instruction.OpCode.Code value

Is there any documentation or is there a part of the cecil source code that I can consult to get a comprehensive view of which Operand types cecil will use for a given Code value? Eg: I can glean from MethodBodyRocks that Ldloc takes an Operand of…
Keith
  • 2,820
  • 5
  • 28
  • 39
8
votes
6 answers

Replacing instructions in a method's MethodBody

(First of all, this is a very lengthy post, but don't worry: I've already implemented all of it, I'm just asking your opinion, or possible alternatives.) I'm having trouble implementing the following; I'd appreciate some help: I get a Type as…
Alix
  • 927
  • 7
  • 21
8
votes
1 answer

Emitting delegate function call

I have the following C# code: public static double f2(Func f, double x) { return f(x); } And here it's IL code: .method public hidebysig static float64 f2 ( class [mscorlib]System.Func`2 f, …
Ivan Kochurkin
  • 4,413
  • 8
  • 45
  • 80
7
votes
1 answer

Mono.Cecil something like Type.GetInterfaceMap?

System.Reflection.Type contains GetInterfaceMap which help to determine what method implement some method from interface. Does Mono.Cecil contain something like this? Or how to implement such behaviour?
WerWolf
  • 124
  • 1
  • 9
7
votes
3 answers

How to determine which methods are called in a method?

I'd like to list all the methods that are called from a specific method. E.g. if I have the following code: public void test1() { test2(); test3(); } The list should contain test2() and test3(). It would be great if methods of the same…
anon
7
votes
1 answer

Member is declared in another module and needs to be imported

I use Mono.Cecil to create a new custom attribute type and then add it to an existing type. To demonstrate it, I have a pre-existing DLL called "Sample" with type that is called "SampleType". I want to use Mono.Cecil to weave in a new type in…
Dudi Keleti
  • 2,946
  • 18
  • 33
7
votes
3 answers

Roslyn / Find References - Can't properly load Workspace

I'm trying to write some code to find all method invocations of any given method as I am looking to create an open source UML Sequence Diagramming tool. I'm having trouble, however, getting past the first few lines of code :/ The API appears to have…
Jordan
  • 5,085
  • 7
  • 34
  • 50
7
votes
1 answer

What do these properties mean in Mono.Cecil?

I am using Lokad shared libraries, which in turn depends on Mono.Cecil. I am a little confused what the following properties mean (they are to do with .NET internals and thus have equivalent .NET internals): PackingSize (they are to do with types…
GurdeepS
  • 65,107
  • 109
  • 251
  • 387
6
votes
1 answer

Mono.Cecil: call GENERIC base class' method from other assembly

I'm following up on my earlier question: Mono.Cecil: call base class' method from other assembly. I'm doing the same thing, but if my base class is generic it doesn't work. //in Assembly A class BaseVM {} //in Assembly B class MyVM :…
TDaver
  • 7,164
  • 5
  • 47
  • 94
6
votes
1 answer

Finding type hierarchy assemblies using Mono.Cecil

I am trying to implement a method that receives a type and returns all the assemblies that contain its base types. For example: Class A is a base type (class A belongs to assembly c:\A.dll) Class B inherits from A (class B belongs to assembly…
Elisha
  • 23,310
  • 6
  • 60
  • 75
6
votes
1 answer

How to store value into a generic class field (Mono.Cecil)

I'm using Mono.Cecil for rewriting some assemblies. Given a generic class with a string field for example. I want to generate code into a method of this class which writes into this field. This is the code to achieve that: var origInstanceField =…
csnemes
  • 121
  • 5
1
2
3
25 26