diff --git a/AUTHORS.md b/AUTHORS.md
index 2724b8203..10b17f157 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -32,6 +32,7 @@
- Sam Winstanley ([@swinstanley](https://github.com/swinstanley))
- Sean Freitag ([@cowboygneox](https://github.com/cowboygneox))
- Serge Weinstock ([@sweinst](https://github.com/sweinst))
+- Ville M. Vainio ([@vivainio](https://github.com/vivainio))
- Virgil Dupras ([@hsoft](https://github.com/hsoft))
- Wenguang Yang ([@yagweb](https://github.com/yagweb))
- Xavier Dupré ([@sdpython](https://github.com/sdpython))
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ac76b5f72..b446cc4b6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
## [unreleased][]
### Added
-
+- Added clr.GetClrType (#432)(#433)
- Added `Foo` feature
### Changed
diff --git a/src/runtime/moduleobject.cs b/src/runtime/moduleobject.cs
index 258d77bac..e683026f9 100644
--- a/src/runtime/moduleobject.cs
+++ b/src/runtime/moduleobject.cs
@@ -403,6 +403,23 @@ public static Assembly AddReference(string name)
return assembly;
}
+ ///
+ /// Get a Type instance for a class object.
+ /// clr.GetClrType(IComparable) gives you the Type for IComparable,
+ /// that you can e.g. perform reflection on. Similar to typeof(IComparable) in C#
+ /// or clr.GetClrType(IComparable) in IronPython.
+ ///
+ ///
+ ///
+ /// The Type object
+
+ [ModuleFunction]
+ [ForbidPythonThreads]
+ public static Type GetClrType(Type type)
+ {
+ return type;
+ }
+
[ModuleFunction]
[ForbidPythonThreads]
public static string FindAssembly(string name)
diff --git a/src/tests/test_module.py b/src/tests/test_module.py
index 2255ea411..e02aa6e01 100644
--- a/src/tests/test_module.py
+++ b/src/tests/test_module.py
@@ -352,6 +352,26 @@ def test_clr_add_reference():
with pytest.raises(FileNotFoundException):
AddReference("somethingtotallysilly")
+def test_clr_get_clr_type():
+ """Test clr.GetClrType()."""
+ from clr import GetClrType
+ import System
+ from System import IComparable
+ from System import ArgumentException
+ assert GetClrType(System.String).FullName == "System.String"
+ comparable = GetClrType(IComparable)
+ assert comparable.FullName == "System.IComparable"
+ assert comparable.IsInterface
+ assert GetClrType(int).FullName == "System.Int32"
+ assert GetClrType(str).FullName == "System.String"
+ assert GetClrType(float).FullName == "System.Double"
+ dblarr = System.Array[System.Double]
+ assert GetClrType(dblarr).FullName == "System.Double[]"
+
+ with pytest.raises(TypeError):
+ GetClrType(1)
+ with pytest.raises(TypeError):
+ GetClrType("thiswillfail")
def test_assembly_load_thread_safety():
from Python.Test import ModuleTest