I can execute a PowerShell script from C# with arguments and receive a return value. However, I'm now looking to use PowerShell more like a scripting language (similar to LUA) in my C# application. Specifically, I want to be able to call in PowerShell methods of my running C# application and return a value.
Some sample code:
The C# application calculates in certain time intervals some data and stores it in Manager.CalculatedData.
public int GetSomeData() => Manager.CalculatedData;
And the PowerShell script should be able to call this method and receive the actual data.
$foo = ? # call to the method of the running C# application
# do something with 'foo'
However, it is important to me that the PowerShell code remains simple so that the user can call the method very easily.
My question is: How can I use C# and PowerShell to achieve this bidirectional interaction?

