File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,27 @@ internal NewReference GetDocString()
48
48
}
49
49
50
50
51
+ /// <summary>
52
+ /// ClassObject __repr__ implementation.
53
+ /// </summary>
54
+ public new static NewReference tp_repr ( BorrowedReference ob )
55
+ {
56
+ if ( GetManagedObject ( ob ) is not CLRObject co )
57
+ {
58
+ return Exceptions . RaiseTypeError ( "invalid object" ) ;
59
+ }
60
+
61
+ var inst = co . inst ;
62
+ var obType = inst . GetType ( ) ;
63
+ if ( obType . IsEnum )
64
+ {
65
+ var repr = string . Format ( "{0}.{1}" , obType . Name , inst . ToString ( ) ) ;
66
+ return Runtime . PyString_FromString ( repr ) ;
67
+ }
68
+
69
+ return ClassBase . tp_repr ( ob ) ;
70
+ }
71
+
51
72
/// <summary>
52
73
/// Implements __new__ for reflected classes and value types.
53
74
/// </summary>
Original file line number Diff line number Diff line change @@ -143,6 +143,13 @@ def test_enum_undefined_value():
143
143
Test .FieldTest ().EnumField = Test .ShortEnum (20 , True )
144
144
145
145
146
+ def test_enum_repr ():
147
+ """Test enumeration repr."""
148
+ from System import DayOfWeek
149
+
150
+ assert repr (DayOfWeek .Monday ) == "Monday"
151
+
152
+
146
153
def test_enum_conversion ():
147
154
"""Test enumeration conversion."""
148
155
ob = Test .FieldTest ()
You can’t perform that action at this time.
0 commit comments