[Python.NET] Can I create extension file by C#?

Feihong Hsu hsu.feihong at yahoo.com
Tue Nov 6 22:16:22 CET 2007

Just make an ordinary C# class, then when you compile it make sure to use the /target:library switch. Once it's inside a .DLL file, you can use that class from IronPython.

C# file (Example.cs):

using System;

namespace Example
    public class ExampleClass
        public void ExampleMethod(int i, string s, DateTime dt)
        Console.WriteLine("{0}, {1}, {2}", i, s, dt);

To compile, run this at the command line (or just compile it in Visual C#):

csc /target:library Example.cs

You will get a file named Example.dll.

The IronPython file (example.py):

import clr

from System import DateTime
from Example import ExampleClass

e = ExampleClass()
e.ExampleMethod(45, "hello", DateTime.Today)

Make sure that example.py is in the same directory as Example.dll (otherwise make sure the directory of Example.dll is in sys.path). BTW, I had problems getting this example working in IronPython 2.0 Alpha 4, I used IronPython 1.1 instead.

- Feihong

jane janet <anakinnani at hotmail.com> wrote:    .hmmessage P { margin:0px; padding:0px } body.hmmessage { FONT-SIZE: 10pt; FONT-FAMILY:Tahoma }   
Hello all,
 I wanna to know that can i create any extension file or DLL file by using C# and if it can I wanna know how to do too.
 Please help me.
 Thank you.

Peek-a-boo FREE Tricks & Treats for You! Get 'em!_________________________________________________
Python.NET mailing list - PythonDotNet at python.org

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythondotnet/attachments/20071106/43aa3208/attachment.htm 

More information about the PythonDotNet mailing list