stormist
stormist

Reputation: 5925

How does Iron Python play (mean or nice) with a C# class?

I am interested in writing a few routines within my C# program in IronPython. I'm concerned about the integration. I have a simple class:

  public class candleStim
  {
    public virtual int       Id            { get; set; }
    public virtual int       candleNumber  { get; set; } 
    public virtual DateTime  date          { get; set; }
    public virtual decimal   open          { get; set; }
    public virtual decimal   high          { get; set; }
    public virtual decimal   low           { get; set; }
    public virtual decimal   close         { get; set; }
    public virtual List<EMA> EMAs          { get; set; } 
    public virtual List<SMA> SMAs          { get; set; }
    public virtual string    simulationID  { get; set; }
   } 

Will a method written in IronPython understand this class? What about a simple string object, are they the same in C# and IronPython? If not, how would I go about converting? Thank you!

Upvotes: 2

Views: 196

Answers (1)

Agat
Agat

Reputation: 4779

You can easily check how nice all that working by your own.

I am not sure what tools are you using, but if you setup IronPython and IronPython Tools for VisualStudion, you can experiment much.

The sample below is just some autogenerated IronPython Winforms project code with a reference to your class, which is built as standard ClassLibrary C# project. (You have to copy the assembly built to the IronPython project directory though).

The only thing I am not sure about is EMA/SMA -- if you expecting those to be some 'standard' Python classes imported from some libraries or just some custom stuff of yours.

import clr
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')

### importing our assembly
clr.AddReference('ClassLibrary1ForPython')

from System.Drawing import *
from System.Windows.Forms import *

from ClassLibrary1ForPython import *

class MyForm(Form):
    def __init__(self):
        # Create child controls and initialize form
        pass

### your class instantiating
classInstance = candleStim()


Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)

form = MyForm()
### setting the window title from the value of a property of your class (standard string)
form.Text = classInstance.simulationID

Application.Run(form)

Upvotes: 1

Related Questions