[IronPython] Extension methods in python

Miha Valencic miha.valencic at gmail.com
Thu Nov 6 18:07:57 CET 2008


Marty, from what I understand you are passing a variable into python engine
and want extension methods there? You can use something like that:

import clr
import System

class MyString(System.String):
  pass;

  def ToFoo(self):
    return self.upper()+' FooBarBaz'


a = MyString("Hello world!");
print a.ToFoo();



That would print "HELLO WORLD! FooBarBaz.

You can't put methods on System.String though, but you can create new object
from System.String...

Miha

2008/11/5 Marty Nelson <Marty.Nelson at symyx.com>

>  Is there the equivalent of extension method in python?  I want to put a
> variable into the script scope and create extension methods for it.  Does
> this make sense and is it possible?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081106/04fadd0c/attachment.html>


More information about the Ironpython-users mailing list