get fields with reflection

前端 未结 3 1875
忘掉有多难
忘掉有多难 2020-12-16 03:51

I want to get all fields that have null values but i aint even getting any fields:

  [Serializable()]
public class BaseClass
{
    [OnDeserialized()]
    int         


        
3条回答
  •  难免孤独
    2020-12-16 04:30

    Type.GetFields methods returns all public fields. Fields that the compiler autogenerates for you are private, so you need to specify correct BindingFlags.

    type.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
    

提交回复
热议问题