jeudi 6 mai 2021

How do I specify Binding Flags to capture fields of type int? [duplicate]

I am trying to figure out why the following code does not retrieve fields of type int?

     private static List<FieldInfo> GetRelevantFields(Type type)
    {
        var myObjectFields = type.GetFields(
            BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
        var nonKeyFields = myObjectFields.ToList();
        var fields = new List<FieldInfo>();
        foreach (var fi in from fi in nonKeyFields
            let colType = ColType(fi)
            where colType != DBColumnType.Unknown // objects and nullable columns will be missed
            select fi) fields.Add(fi);
        return fields;
    }

For example if I use

public class MyBusinessObject 
{ 
   public int? LookupId { get; set; } // this binding will not be retreived
   public int  Lookup2Id {get;set;} // this binding will be retreived
}

How do I get it to?

Looking at the decompiled code

Binding Flags





Aucun commentaire:

Enregistrer un commentaire