I've got the following class:
public sealed class ImmutableObject {
public readonly int ic;
public ImmutableObject(int value) {
ic = value;
}
}
Then I created a method that tries to obtain reflection informations by this class:
public static void infosByImmutableObject() {
ImmutableObject iobj = new ImmutableObject(1);
Console.WriteLine(iobj.ic);
Type typeIobj = iobj.GetType();
PropertyInfo infos = typeIobj.GetProperty("ic");
}
I can't undestand why, altough ic is public, infos remains null, and if I try with Type.getProperties the resulting array has zero elements. I noticed that, whitout the readonly modifier, GetProperties("ic") returns. How a public field is seen by GetProperty() when the readonly is present?
Aucun commentaire:
Enregistrer un commentaire