File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 2
2
using System . Collections . Generic ;
3
3
using System . Threading ;
4
4
5
+ using Python . Runtime ;
6
+
5
7
namespace Python . Test
6
8
{
7
9
public interface IInterfaceTest
@@ -215,6 +217,30 @@ public static object InvokeCtor(Type t)
215
217
return obj ;
216
218
}
217
219
220
+ public object TestObj { get ; set ; }
221
+
222
+ public static object TestOnType ( Type t )
223
+ {
224
+ using ( Py . GIL ( ) )
225
+ {
226
+ var obj = ( SimpleClass ) Activator . CreateInstance ( t ) ;
227
+ //obj = obj.ToPython().As<SimpleClass>();
228
+ obj . TestObj = new object ( ) ;
229
+ var py = obj . ToPython ( ) ;
230
+ var man = py . As < SimpleClass > ( ) ;
231
+ if ( ! ReferenceEquals ( man , obj ) )
232
+ throw new Exception ( "Same object expected" ) ;
233
+ var setObj = py . GetAttr ( "TestObj" ) . As < object > ( ) ;
234
+ if ( setObj == null )
235
+ throw new NullReferenceException ( ) ;
236
+ if ( ReferenceEquals ( setObj , obj . TestObj ) == false )
237
+ throw new Exception ( "!!" ) ;
238
+
239
+
240
+ return obj ;
241
+ }
242
+ }
243
+
218
244
public static void Pause ( )
219
245
{
220
246
Original file line number Diff line number Diff line change @@ -361,9 +361,27 @@ class ClassWithAttributes3(ISimpleInterface, SimpleClass):
361
361
362
362
c = ClassWithAttributes2 ()
363
363
c2 = ClassWithAttributes3 ()
364
+
365
+ def test_subclass_ctor ():
366
+ import clr
367
+ class SubClass0 (SimpleClass ):
368
+ pass
369
+ class SubClass1 (SubClass0 ):
370
+ def __init__ (self ):
371
+ super ().__init__ ()
372
+ class SubClass2 (SubClass1 ):
373
+ __namespace__ = "TestModule"
374
+ def __init__ (self ):
375
+ super ().__init__ ()
376
+ SimpleClass .TestOnType (SubClass0 )
377
+ SimpleClass .TestOnType (SubClass1 )
378
+ SimpleClass .TestOnType (SubClass2 )
379
+
364
380
def test_more_subclasses ():
365
381
import clr
366
- class SubClass1 (SimpleClass ):
382
+ class SubClass0 (SimpleClass ):
383
+ pass
384
+ class SubClass1 (SubClass0 ):
367
385
X = clr .property (Double , 1.0 )
368
386
def __init__ (self ):
369
387
super ().__init__ ()
@@ -379,6 +397,9 @@ def __init__(self):
379
397
super ().__init__ ()
380
398
def IncrementThing (self ):
381
399
return 6 ;
400
+ SimpleClass .TestOnType (SubClass0 )
401
+ SimpleClass .TestOnType (SubClass1 )
402
+ SimpleClass .TestOnType (SubClass2 )
382
403
obj = SimpleClass .InvokeCtor (SubClass2 )
383
404
384
405
obj2 = SubClass2 ()
You can’t perform that action at this time.
0 commit comments