File tree Expand file tree Collapse file tree 4 files changed +39
-1
lines changed
Expand file tree Collapse file tree 4 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 3232- Sam Winstanley ([ @swinstanley ] ( https://github.com/swinstanley ) )
3333- Sean Freitag ([ @cowboygneox ] ( https://github.com/cowboygneox ) )
3434- Serge Weinstock ([ @sweinst ] ( https://github.com/sweinst ) )
35+ - Ville M. Vainio ([ @vivainio ] ( https://github.com/vivainio ) )
3536- Virgil Dupras ([ @hsoft ] ( https://github.com/hsoft ) )
3637- Wenguang Yang ([ @yagweb ] ( https://github.com/yagweb ) )
3738- Xavier Dupré ([ @sdpython ] ( https://github.com/sdpython ) )
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
88## [ unreleased] [ ]
99
1010### Added
11-
11+ - Added clr.GetClrType ( # 432 )( # 433 )
1212- Added ` Foo ` feature
1313
1414### Changed
Original file line number Diff line number Diff line change @@ -403,6 +403,23 @@ public static Assembly AddReference(string name)
403403 return assembly ;
404404 }
405405
406+ /// <summary>
407+ /// Get a Type instance for a class object.
408+ /// clr.GetClrType(IComparable) gives you the Type for IComparable,
409+ /// that you can e.g. perform reflection on. Similar to typeof(IComparable) in C#
410+ /// or clr.GetClrType(IComparable) in IronPython.
411+ ///
412+ /// </summary>
413+ /// <param name="type"></param>
414+ /// <returns>The Type object</returns>
415+
416+ [ ModuleFunction ]
417+ [ ForbidPythonThreads ]
418+ public static Type GetClrType ( Type type )
419+ {
420+ return type ;
421+ }
422+
406423 [ ModuleFunction ]
407424 [ ForbidPythonThreads ]
408425 public static string FindAssembly ( string name )
Original file line number Diff line number Diff line change @@ -352,6 +352,26 @@ def test_clr_add_reference():
352352 with pytest .raises (FileNotFoundException ):
353353 AddReference ("somethingtotallysilly" )
354354
355+ def test_clr_get_clr_type ():
356+ """Test clr.GetClrType()."""
357+ from clr import GetClrType
358+ import System
359+ from System import IComparable
360+ from System import ArgumentException
361+ assert GetClrType (System .String ).FullName == "System.String"
362+ comparable = GetClrType (IComparable )
363+ assert comparable .FullName == "System.IComparable"
364+ assert comparable .IsInterface
365+ assert GetClrType (int ).FullName == "System.Int32"
366+ assert GetClrType (str ).FullName == "System.String"
367+ assert GetClrType (float ).FullName == "System.Double"
368+ dblarr = System .Array [System .Double ]
369+ assert GetClrType (dblarr ).FullName == "System.Double[]"
370+
371+ with pytest .raises (TypeError ):
372+ GetClrType (1 )
373+ with pytest .raises (TypeError ):
374+ GetClrType ("thiswillfail" )
355375
356376def test_assembly_load_thread_safety ():
357377 from Python .Test import ModuleTest
You can’t perform that action at this time.
0 commit comments