Your
Calculation
class does not contain a parameterless constructor. You need to pass the constructor parameters to
the PrivateObject
constructor[
^]:
string expression = "5*10-18/(3+19)";
PrivateObject obj = new PrivateObject(
typeof(Calculation),
new[] { typeof(string) },
new[] { expression });
You're also trying to invoke the
sendNumberToCalculation
method with one parameter of the
PolishNotation
type, but that method doesn't have any parameters. You need to remove the second argument from the
Invoke
call:
double actual = Convert.ToDouble(obj.Invoke("sendNumberToCalculation"));