[Mono-list] ves_icall_FieldInfo_SetValueInternal
Robert Jordan
robertj at gmx.net
Mon Sep 18 09:56:50 EDT 2006
Paolo Molaro wrote:
> On 09/15/06 Bruce Wilkie wrote:
>> i'm seeing a bug where setting a static field uses the class the field is on:
>> --------------
>> MonoVTable *vtable = mono_class_vtable (mono_object_domain (field), field->klass);
>> --------------
>>
>> consider, however, that the static field is coming from a base class.
>> in this case, it seems that vtable should really be the vtable of the
>> base class?
>
> Yes, if a static field is defined in class A, you need to use the vtable
> of class A to access it. To get the class that defines a field, use the
> parent member of the MonoClassField structure.
> I have fixed the code in metadata/icall.c: do you have a test case where
> you get a MonoReflectionField object for a static field with klass
> being a derived class?
> Thanks.
using System;
using System.Reflection;
public class A
{
public static int X = 0;
}
public class B : A
{
static void Main ()
{
BindingFlags bf = BindingFlags.Public |
BindingFlags.Static |
BindingFlags.FlattenHierarchy;
foreach (FieldInfo fi in typeof (B).GetFields (bf)) {
fi.SetValue (null, 42);
Console.WriteLine (X == 42);
}
}
}
Robert
More information about the Mono-list
mailing list