This is an update from my original post: http://blogs.msdn.com/saveenr/archive/2008/11/14/consuming-extension-methods-in-ironpython.aspx
Before proceeding, please read the original article. It will help in understanding this one.
We have two assemblies. One assembly (the extender) contains extension methods that are assigned to a class in the other assembly (the extended).
And here is the corresponding source code
At this point both C# and F# can consume the extension methods defined in ClassLibB.
IronPython requires us to add the “ExtensionType” attribute.
Our first attempt is this.
And the source code looks like this …
And now IronPython can consume the extension methods.
As you can see, I had to modify the source code of Assembly B. In a lot of real-world situations it’s not possible to modify Assembly A or B.
Here are some reasons why:
It this point, we’re stuck – but here’s the great news. Those ExtensionType attributes don’t have to be in either Assembly A or Assembly B. You can create a special Assembly C that has the sole purpose of storing these attributes. If you load Assembly C then IronPython can see the extension methods and it doesn’t require any changes to Assembly A or Assembly B.
And the source code looks like this:
Add a reference to AssemblyC and then import it. Then the extension methods will be visible to IronPython