Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39e4673

Browse files
vivainiovmuriart
authored andcommitted
Support clr.GetClrType() - as in IronPython (#433)
* Support clr.GetClrType() - as in IronPythonImplements#432* Tests for clr.GetClrType()* clr.GetClrType test: ensure bad type raises ArgumentException* clr.GetClrType - added xml doc comment, updated AUTHORS.md and CHANGELOG.md* Simplified implementation of clr.GetClrType (taken from IronPython)
1 parentc8f3756 commit39e4673

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

‎AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
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))

‎CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

‎src/runtime/moduleobject.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,23 @@ public static Assembly AddReference(string name)
403403
returnassembly;
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+
publicstaticTypeGetClrType(Typetype)
419+
{
420+
returntype;
421+
}
422+
406423
[ModuleFunction]
407424
[ForbidPythonThreads]
408425
publicstaticstringFindAssembly(stringname)

‎src/tests/test_module.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,26 @@ def test_clr_add_reference():
352352
withpytest.raises(FileNotFoundException):
353353
AddReference("somethingtotallysilly")
354354

355+
deftest_clr_get_clr_type():
356+
"""Test clr.GetClrType()."""
357+
fromclrimportGetClrType
358+
importSystem
359+
fromSystemimportIComparable
360+
fromSystemimportArgumentException
361+
assertGetClrType(System.String).FullName=="System.String"
362+
comparable=GetClrType(IComparable)
363+
assertcomparable.FullName=="System.IComparable"
364+
assertcomparable.IsInterface
365+
assertGetClrType(int).FullName=="System.Int32"
366+
assertGetClrType(str).FullName=="System.String"
367+
assertGetClrType(float).FullName=="System.Double"
368+
dblarr=System.Array[System.Double]
369+
assertGetClrType(dblarr).FullName=="System.Double[]"
370+
371+
withpytest.raises(TypeError):
372+
GetClrType(1)
373+
withpytest.raises(TypeError):
374+
GetClrType("thiswillfail")
355375

356376
deftest_assembly_load_thread_safety():
357377
fromPython.TestimportModuleTest

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp