I am trying to implement a solution where I have a predefined calculation against an item, this calculation may be different for each individual item this is why I was planning to do it this way.
Is it possible to pass in this calculation with string interpolation whilst still retaining the reference to the variables?
I've simplified this for ease of reading here but the principle is the same, these are the parameters being passed in:
double individualTotal = 100;
double parentTotal = 2000;
double siblingTotal = 1500;
double anotherTotal = 100;
The calculation would be stored as text in the database for example:
(siblingTotal/parentTotal)*individualTotal
Or another calculation could be:
((siblingTotal/(parentTotal)*individualTotal)+(anotherTotal*0.5)
I have tried the following with no luck, it just outputs the text:
var calculationText = "{(siblingCalculationTotalValue/parentCalculationTotalValue)*individualTotalValue}";
var calculation = $"" + calculationText + ""
And:
var calculationText = "{(siblingCalculationTotalValue/parentCalculationTotalValue)*individualTotalValue}";
var calculation = $"{calculationText}"
Both output:
"CalculatedValue": "{(siblingCalculationTotalValue/parentCalculationTotalValue)*individualTotalValue}"
I have also tried:
var calculationText = "(siblingCalculationTotalValue/parentCalculationTotalValue)*individualTotalValue";
var calculation = $"{calculationText}"
Output:
"CalculatedValue": "(siblingCalculationTotalValue/parentCalculationTotalValue)*individualTotalValue"
This works as expected when I pass the parameters directly into the string interpolation however it doesn't allow for the variability in calculations:
var calculation = $"{(siblingCalculationTotalValue/parentCalculationTotalValue)*individualTotalValue}"
Output:
"CalculatedValue": "75"
Any help would be really appreciated!