What is the syntax for defining an array literal in CIL for the purposes of decorating a member with a custom attribute?
I am writing some .NET code in CIL (using ilasm.exe to compile it) and I need to decorate a method with a custom attribute. The constructor for that attribute takes an array of integers as its only parameter. How can I do this in CIL?
This is the signature of the custom attribute's constructor (I can't change it):
public FooAttribute(int[] values) {
// some hidden constructor stuff
}
This is how I'd decorate my method if I were writing in C# (but I can't):
[Foo(new int[] {1, 2, 3, 4})]
public string Bar() {
return "Some text";
}
Using ildasm.exe to look at the compiled C# (to try and understand by reverse engineering) gives me an ugly and unusable binary literal. I tried using Reflector.NET instead and it looks much better but ilasm.exe throws a syntax error at the keyword "new" so I can't use it:
.custom instance void SomeNamespace.FooAttribute::.ctor(int32[]) = { new int32[int32(4)] { int32(1), int32(2), int32(3), int32(4) } }