I'm currently working on a C# MVC5 application. I've managed to contain almost all of the Business logic rules to the ViewModel, Model (attributes only), and Store Procedures.
That being said I have a static class that exports an class to CSV (and later other types). This exporter uses Reflection using the DisplayAttribute for Name and Order.
The totals are calculated and stored in the ViewModels, which currently the Exporter doesn't use aside from acquiring the initial list of models. My goal is to append a totals row to the exported file while maintaining a good OOP design. I see two possible paths that I can take:
- Send the totals with the initial list of models to the exporter.
- Calculate the totals in the exporter using a CustomAttribute to indicate which totals to calculate.
Pros/Cons of Method #1:
- Doesn't use Reflection
- Requires the order and spacing of columns for totals row to be known in the ViewModel, which I'm trying to keep that knowledge purely in the Models (attributes).
Pros/Cons of Method #2:
- Uses Reflection; However the Exporter already uses reflection and it's faster than previous methods and easier to maintain.
- Some of our totals are just simple sums or counts. For example we have one that is
Sum(P1) / (Sum(P2) + Sum(P3))
. In this case I was thinking we could make the attribute store the formula using property names (since we're already using reflection) and parse the formula to calculate it. This would require the writing/maintaining of a parser, and might actually increase the time the exporter takes quite a bit.
Question:
Is there a way to add a totals row to my exporter while keeping the following?
- Totals logic remaining in the ViewModel.
- Column/Positioning Logic remaining in the Model(attributes).
- Exporter remaining "generic" (via Reflection).
Aucun commentaire:
Enregistrer un commentaire