| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c8f3756 commit 39e4673
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ | |||
| 32 | 32 | - Sam Winstanley ([@swinstanley](https://github.com/swinstanley)) | |
| 33 | 33 | - Sean Freitag ([@cowboygneox](https://github.com/cowboygneox)) | |
| 34 | 34 | - Serge Weinstock ([@sweinst](https://github.com/sweinst)) | |
| 35 | + - Ville M. Vainio ([@vivainio](https://github.com/vivainio)) | ||
| 35 | 36 | - Virgil Dupras ([@hsoft](https://github.com/hsoft)) | |
| 36 | 37 | - Wenguang Yang ([@yagweb](https://github.com/yagweb)) | |
| 37 | 38 | - 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][]. | |||
| 8 | 8 | ## [unreleased][] | |
| 9 | 9 | ||
| 10 | 10 | ### Added | |
| 11 | - | ||
| 11 | + - Added clr.GetClrType (#432)(#433) | ||
| 12 | 12 | - Added `Foo` feature | |
| 13 | 13 | ||
| 14 | 14 | ### Changed | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -403,6 +403,23 @@ public static Assembly AddReference(string name) | |||
| 403 | 403 | return assembly; | |
| 404 | 404 | } | |
| 405 | 405 | ||
| 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 | + | ||
| 406 | 423 | [ModuleFunction] | |
| 407 | 424 | [ForbidPythonThreads] | |
| 408 | 425 | 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(): | |||
| 352 | 352 | with pytest.raises(FileNotFoundException): | |
| 353 | 353 | AddReference("somethingtotallysilly") | |
| 354 | 354 | ||
| 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") | ||
| 355 | 375 | ||
| 356 | 376 | def test_assembly_load_thread_safety(): | |
| 357 | 377 | from Python.Test import ModuleTest | |
| Back | FazBrowse Home | New Git URL |
0 commit comments