Replies: 2 comments
-
Hi, I'm not sure I fully understand what it is you're after. For the above code, you can write something like:
In instructions, you'll find a method call to |
Beta Was this translation helpful? Give feedback.
-
A method invocation in IL will be preceded by instructions that set up the arguments on the stack. As Jb says, you will be able to find the call to the superclass constructor fairly easily, and that will tell you how many arguments it expects (the first of which will be the In your simple case, where every argument is either a literal or one of the arguments of the subclass constructor, that's pretty easy - you get one instruction per parameter (ldc to load a constant, ldarg to load an argument):
(bit surprising that GitHub doesn't do IL for highlighting) However, things can get more complicated; consider public static readonly int X = 5;
public MyClass()
: base(MathF.PI, MathF.E, MathF.Tau, MathF.Atan2(13.0f, 42.0f), Color.Bisque, Color.FromArgb((3 * MyClass.X) + 7, 2, 3, 4)) {
}
private int evil = 666; will get you
so not only will there be code preceding the base constructor call (i.e. any and all initializers for instance fields), but the instructions before it are much more complex, including method calls of their own. In short, trying to make sense of the exact expressions passed to a method's arguments, while certainly possible, is not a trivial undertaking. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm looking for a way to get the 'base' parameters of constructor class using a dll without reference.
seem's like this information can't be found with reflection. (see my inital post here : https://stackoverflow.com/questions/68578435/c-sharp-constructor-get-base-part-with-reflection)
do cecil allow to get method content ?
and is there a way to get the information about the base constructor call with its parameters value ?
Exemple showing what i call 'base' constructor (not shure how to call it)
Exemple of what i try to watch in debug with cecil, but i don't really get how to retrieve the method content...
Beta Was this translation helpful? Give feedback.
All reactions