Extracting json report info to a helper class RRS feed

  • Question

  • User-1314300104 posted

    I have several json reports that are being generated in the following format, with similar header information but the returned data lists are of different custom types.
    I want to write a generic helper class that can be used to replace all the individual header information, the majority of which is the same.
    I also want to be able to pass in different data lists for the different reports. So creating a set helper class is no good.


    The report code:

    public static CreateReport1 CreateHeader(List<CustomLevelReport> reportData)
    CreateReport1 newReport = new CreateReport1 ();
    newReport.TotalQuantity = reportData.Sum(x => x.Quantity);
    newReport.TotalNet = reportData.Sum(x => x.Net);
    newReport.TotalVat = reportData.Sum(x => x.Vat);
    newReport.TotalGross = reportData.Sum(x => x.Gross); //<-- This header info mostly repeates for each report
    //Then the report data is added
    newReport.data = reportData //<-- this List type forms the body and would be different for each report
    return newReport;

    Instead I would like to call a hepler class for each report that automatically lists out the header part if not the data List, but I would like to pass that is as well, if possible.


    public static CreateReport1 CreateHeader(List<CustomLevelReport> reportData) // This code needs to be generic not fixed to each report tytpe
    CreateReport1 newReport = new CreateReport1 ();
    newReport = helper(reportData);
    return newReport; <-- Returning the report with the header info with the specifyed List type data.

    Is there a simple 'best' way to do this, giver the input List would not always be of the same type?

    Wednesday, November 25, 2015 7:36 PM

All replies

  • User-2057865890 posted


    According to your description and code,I think there is no simple 'best' way.

    Best regards,

    Chris Zhao

    Thursday, December 3, 2015 9:53 AM