Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Extracting json report info to a helper class

$
0
0

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.

e.g.

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.

e.g.

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?


Viewing all articles
Browse latest Browse all 4850

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>