Why does getFields () return nothing?

I am trying to get the public properties of an object but returning nothing. Can you tell me what I'm doing wrong.

public class AdHocCallReportViewModel : ReportViewModel
{
    public string OperatorForCustEquipID { get; set; }
    public string OperatorForPriorityID { get; set; }
    public string OperatorForCallTypeID { get; set; }
    public string OperatorForStatusID { get; set; }
}

public UpdateReportParameters(AdHocCallReportViewModel rvm)
{
    var type = rvm.GetType();
    foreach (var f in type.GetFields().Where(f => f.IsPublic))
    {
        Console.WriteLine(f.Name);
        Console.WriteLine(f.GetValue(rvm).ToString());
    }
}  

When passing through the code, it skips the foreach loop because GetFields returns null elements.

+5
source share
3 answers

You have no public fields. These are properties. So try it type.GetProperties().

+23
source

Are you trying to get the fields, try calling GetProperties()

+8
source

Pass BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, .

-, , . . , , .

+1