.netlistdatasetfastmember

HyperPropertyDescriptor issue with .net framework 4.5.2


am trying to convert a list of objects to datatable and am using the solution given in this response https://stackoverflow.com/a/5805044/1447718.

i downloaded hyperproperty and recompiled it to 4.5.2 and used that in my application. when i execute the method, am getting empty dataset with one column. On debugging, i found that the line

PropertyDescriptorCollection properties =
            TypeDescriptor.GetProperties(typeof(T));

is giving properties object with count 0.
i tried replacing the line with

PropertyDescriptorCollection properties =
            TypeDescriptor.GetProperties(data.First().GetType()); 

still no luck.

can anyone help? thanks.


Solution

  • From comments:

    public class RequestData {
        public string d;
        public DataType t;
        public int i;
    }
    

    These are fields, not properties. The PropertyDescriptor model focuses on properties, and frankly public fields are just an anti-pattern. Consider making these into properties. At the simplest, just add {get;set;} after each, and you're done.

    public class RequestData {
        public string d {get;set;}
        public DataType t {get;set;}
        public int i {get;set;}
    }
    

    Personally I'd rename them to be more meaningful, but that won't change how they work.