C # Generics with parameters like IronPython

So the situation is that I have a common C # class named Foo with the template parameter T , which has a new() constraint. I declared my classes something like this:

 class Baz { public Baz() { } } class Foo<T> where T : Baz, new() { // blah blah } 

And in Python:

 class Bar(Baz): def __init__(self): """ do various things here """ 

However, if in Python I try to execute Foo[Bar] , I get an error message indicating that my Bar class violates the restrictions (namely the new() restriction on Foo<T> .

What gives?

+4
source share
1 answer

There is no default constructor for IronPython objects. They need to carry some kind of additional mutable state with them, the type of Python that should be provided when instantiating the class. This type is used to resolve any virtual overloads and other methods in a dynamic call.

+2
source

All Articles