[IronPython] How to do the typeof( ) call on an IronPython implemented class in C#?

Jan R janrou at gmail.com
Tue Feb 17 13:54:54 CET 2009


>
> Can't you do the following?
>
> ServiceHost selfHost = new ServiceHost(typeof(ICalculator), baseAddress);
>
>
> Michael
>
>>
 No!

The class given as parameter to typeof(..) have to implement the interface.
The interface is the service contract, which the server implements.

I have worked around the problem with a stub, that loads and runs the python
script, see attachment. For each stubbed method it calls the python
implemented method:

It would be smart to get rid of the stub.


Regards
Jan Rouvillain

C# stub:

  public class CalculatorServiceStub : ICalculator
  {
    private ICalculator pyCalc;
    public CalculatorServiceStub()
    {
      if (Program.pyr != null)
      {
        Program.pyr.loadscript(@"..\..\..\Calculator\Calculator.py");
        Program.pyr.run();
        pyCalc = (ICalculator)Program.pyr.getInstance("PyCalculator");
      }
    }
    public double Add(double n1, double n2)
    {
      return pyCalc.Add(n1,n2);
    }
    public double Subtract(double n1, double n2)
    {
      return pyCalc.Subtract(n1, n2);
    }
    public double Multiply(double n1, double n2)
    {
      return pyCalc.Multiply(n1, n2);
    }
    public double Divide(double n1, double n2)
    {
      return pyCalc.Divide(n1, n2);
    }
 }

The class PythonRunner is an adapter for loading, compiling, excuting,
instantiating objects and exchanging variables in and out of the script
Calculator.py.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090217/8b737d26/attachment.html>


More information about the Ironpython-users mailing list