I'd suggest to obfuscate the calculations within the class itself.
Add a constructor
and pass SubtractedValues and CurrentQuantity, and use a multiplication function to set the columns:
Note that this solution still only does the calculations once and sets the results to all of your ColN
properties at time of instantiation.
public class StockForecastReportExport
{
public StockForecastReportExport(
string materialName,
int currentStockLevel,
int orderThreshold,
int averageUsage,
int quantityReserved,
int currentQuantity,
int subtractedValues)
{
MaterialName = materialName;
CurrentStockLevel = currentStockLevel;
OrderThreshold = orderThreshold;
AvarageUsage = averageUsage;
QuantityReserved = quantityReserved;
Func<int, int> multiplyFunc = mf =>
currentQuantity - (subtractedValues * mf);
// Calculate the rest
Col1 = multiplyFunc(1);
Col2 = multiplyFunc(2);
Col3 = multiplyFunc(3);
...
}
[ExcelCol("A")]
public string MaterialName { get; set; }
...
}
Then your creation code will be much more elegant:
exportedFile.Rows.Add(
new StockForecastReportExport
(
materialName: stockMaterial.MaterialName,
currentStockLevel: initialQuantity,
orderThreshold: stockMaterial.OrderThreshold,
averageUsage: stockMaterial.AvarageUsage,
quantityReserved: stockMaterial.QuantityReserved,
currentQuantity: stockMaterial.CurrentQuantity,
subtractedValues: subtractedValues
);
);