[Mono-list] Are constants accessible via reflection?

Paolo Molaro lupus@ximian.com
Mon, 5 Aug 2002 15:19:06 +0200

On 08/05/02 Holger Arnold wrote:
> for a research project I'm developing a compiler that targets the CLI. This 
> compiler, which is developed partly in C# using Mono, has to store additional 
> semantic information in the compiled PE files. The information will be stored 
> either in the Constant table (0x0B), or in the data section of the PE file, 
> referenced through the FieldRVA table (0x1D).

You could also use custom attributes.

> The questions I have are, (i) are there any real differences 
> (advantages/disadvantages) between storing this data in the Constants table 
> or in the data section, and (ii) does anyone know if data stored this way is 

The constant table can hold only simple types, while you can set an
arbitrary blob of data in the FieldRVA table.

> accessible via the standard System.Reflection mechanism, or if I have to use 
> a more low-level metadata library?

field.GetValue() should work.
See also how the C# compiler handles array initialization like:
	int[] array = {0, 1, 2, 3, 4, 5, 6};

> There should be a way to access such data via System.Reflection, as at least 
> constants can easily be generated via the SetConstant() method of the 
> System.Reflection.Emit.FieldBuilder class, but I'm unable to find out how.

There is also SetRVAData().


lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better