Question

Can anyone tell me if its possible to redeclare a C# class in IronPython? If I have a C# class, would I be able to monkey-patch it from IronPython?

Was it helpful?

Solution

You cannot monkey patch from IronPython. IronPython treats all .NET classes just like CPython treats built-in types: they cannot be monkey patched. IronRuby on the other hand does support this.

OTHER TIPS

You can monkey-patch from IronPython, but IPy is the only environment that will respect your changes; i.e. if you tried to mock out File.Create from IronPython, this would work fine for any IPy code, but if you called a C# method which called File.Create, it would get the real one, not the mock.

Why would you redeclare it? Wouldn't it make more sense to subclass it or just make a totally new class?

EDIT: Give your clarification, I think what you actually need is a proper inversion of control (IOC) framework, such as Castle Windsor. Basically, you have a database interface, then configure the IOC framework to inject a real database for production, and mock database for testing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top