Im fairly new to .net and would love to get some help with reflection. I have searched everywhere and i cant seem to get this right.
I've got a function which takes in a generic list of my custom class and i am iterating over extracting the properties of the classes and creating a spreadsheet. My issue is when i try to get the value of the property, i get an exception saying 'Object does not match the target value'.
I know this might be a duplicate but i was unable to find anything and any help would be greatly appreciated.
private static Task<SheetData> GenerateSheetDataPart<T>(List<T> data){
//some speadsheet logic
foreach (var dataModel in data){
//some more spreadsheet logic
Type type = dataModel.GetType();
PropertyInfo[] props = type.GetProperties();
foreach (var prop in props){
cell.DataType = await ResolveCellDataTypeOnValue((string)prop.GetValue(prop)); //exception here. function returns Number or String based what value is.
cell.CellValue = new CellValue((string)prop.GetValue(prop);
}
}
}
Aucun commentaire:
Enregistrer un commentaire