I have a whole series of classes which look like
public class ReadVersionCommand : Command
{
public ReadVersionCommand() : base(0x00, 0x01, 0x00, null) { }
}
public class DisplayTextCommand : Command
{
public DisplayTextCommand(byte[] data) : base(0x05, 0x00, 0x00, data) { }
}
public class ReadKeyCommand : Command
{
public ReadKeyCommand(byte p3, byte[] data) : base(0x09, 0x00, p3, data) { }
}
I want to iterate over all these classes, and generate information based on the four parameters to the base Command
class (which I don't have control over). Ideally, I'd do this at runtime, so that we can add more subclasses to Command
and have them automatically show up the next time we run the code.
I know how to use reflection iterate all the classes in question.
I know how to take each Type
object and get the constructor.
I know how to take each ConstructorInfo
object and get the parameters passed to the constructor, both the types and the names. I need to differentiate between a constructor which has one byte p2
parameter and one which has one byte p3
, and I can do that.
I know how to get the base Command
class's constructor, and list the types and names (byte p1, byte p2, byte p3, byte[] data
).
If there were any code in the body of each constructor, I know how to get it with GetMethodBody()
.
However, I can't find any way to tell that each constructor is actually calling the base(byte, byte, byte, byte[])
constructor, and I can't find any way to see what the static values which are being passed to are. The values themselves are "magic" values which mean things to the underlying class, but only in combination. (i.e. 0x00, 0x01, 0x00
means one thing, and 0x01, 0x00, 0x00
means something very different.)
How can I get the values passed to the base constructor using reflection?