[IronPython] Extension methods in python

Marty Nelson Marty.Nelson at symyx.com
Fri Nov 7 04:18:25 CET 2008

I actually want to use an object instance of a .NET custom class that I
pass in before the script is invoked from c#.  Our current scripts look
something like:


row.PropertySet["Foo"]["Bar"].Value = x


and it would be much better if script authors could write:


row.Foo.Bar = x


So I'm looking to have an on the fly function read the metadata of
expected keys and then code generated python class wrapper for the
script author to consume. 



From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Miha Valencic
Sent: Thursday, November 06, 2008 9:08 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Extension methods in python


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

import clr
import System

class MyString(System.String):

  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...


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?


Notice: This e-mail message, together with any attachments, contains
information of Symyx Technologies, Inc. or any of its affiliates or
subsidiaries that may be confidential, proprietary, copyrighted,
privileged and/or protected work product, and is meant solely for
the intended recipient. If you are not the intended recipient, and
have received this message in error, please contact the sender
immediately, permanently delete the original and any copies of this
email and any attachments thereto.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081106/80d982b8/attachment.html>

More information about the Ironpython-users mailing list