属性返回具有零元素的数组

时间:2013-12-13 02:32:06

标签: c# list properties

我有一个有很多列表作为属性的类。当我使用此代码获取PropertiesInfo时,它返回的元素为零元素。

Type type = import.GetType();
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance |BindingFlags.Public);

我试过this,但我仍有同样的问题。

这是我的班级

public class ImportModel
{
    //REFERENSI
    //Level Area
    public List<LevelArea> lsLvlArea;

    //MASTER
    //Area
    public List<Area> lsArea;

    //Region
    public List<Customer> lsCustomer;

    //Branch
    public List<Product> lsProduct;

    //Distributor
    public List<Employee> lsEmployee;

    //Bank
    public List<Device> lsDevice;

    public ImportModel()
    {
        //Referensi
        lsLvlArea = new List<LevelArea>();

        //Master
        lsArea = new List<Area>();
        lsCustomer = new List<Customer>();
        lsDevice = new List<Device>();
        lsEmployee = new List<Employee>();
        lsProduct = new List<Product>();
    }
}

我用谷歌搜索它并没有找到解决方案。请帮帮我。

1 个答案:

答案 0 :(得分:1)

这是因为这些都不是属性,而是字段。你需要打电话

FieldInfo[] properties = type.GetFields(BindingFlags.Instance | BindingFlags.Public);

或者,您可以将字段设为自动属性:

public List<Device> lsDevice {get; set;}