[Mono-devel-list] problems with Reflection and private fields

Leonardo S. leods at cwazy.co.uk
Fri Oct 17 12:53:39 EDT 2003

I have problems retrieving private fields with reflection. I wrote a
small class with 2 private fields, and then try to print their names
using reflection. The problems is, the method GetFields() returns an
empty array. The class is this: 
using System;
using System.Reflection;

public class Borrar
  int attrib1;
  string attrib2;

  public static void Main(string[] args)
    Type type = typeof(Borrar);
    FieldInfo[] info = type.GetFields();

    foreach (FieldInfo i in info)
      Console.WriteLine("----> " + i.Name);


I've also tried using type.GetField(BindingFlags.NonPublic) with the
same result. 

:: Leonardo S. De Seta

More information about the Mono-devel-list mailing list