[Mono-list] Reflection...

Giuseppe Greco giuseppe.greco@agamura.com
Fri, 20 Feb 2004 20:06:26 +0100


Hi all,

since const fields are implicitly static,
the following code fragment should work fine:

public class MyClass
{
  [Accessible] private const int MyConst = 1;
  ..
  public GetMyConst()
  {
    FieldInfo fieldInfo =
      myType.GetType().GetField("MyConst",
        BindingFlags.Static | BindingFlags.NonPublic);

    AccessibleAttribute[] attributes =
      fieldInfo.GetCustomAttributes(
        typeof(AccessibleAttribute), true)
          as AccessibleAttribute[];

    return attribute.Lenght > 0
      ? Convert.ToInt32(fieldInfo.GetValue(this))
      : -1;
  }
}

... but it doesn't! To have the code above working,
I've to replace the "const" keyword with "static"...

Is that a bug, or am I missing something?

Thanks,
j3d.

-- 
----------------------------------------
Giuseppe Greco

::agamura::

phone:  +41 91 604 67 65
mobile: +41 76 390 60 32
email:  giuseppe.greco@agamura.com
web:    www.agamura.com
----------------------------------------