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

Commit7870a9f

Browse files
authored
Ensure methods of Object are also available on interface objects (#1284)
1 parent2e6d12f commit7870a9f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ details about the cause of the failure
3232
- Indexers can now be used with interface objects
3333
- Fixed a bug where indexers could not be used if they were inherited
3434
- Made it possible to use`__len__` also on`ICollection<>` interface objects
35+
- Made it possible to call`ToString`,`GetHashCode`, and`GetType` on inteface objects
3536

3637
###Removed
3738

‎src/runtime/classmanager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,17 @@ private static ClassInfo GetClassInfo(Type type)
341341
}
342342
}
343343
}
344+
345+
// All interface implementations inherit from Object,
346+
// but GetMembers don't return them either.
347+
varobjFlags=BindingFlags.Public|BindingFlags.Instance;
348+
foreach(varmiintypeof(object).GetMembers(objFlags))
349+
{
350+
if(local[mi.Name]==null)
351+
{
352+
items.Add(mi);
353+
}
354+
}
344355
}
345356

346357
for(i=0;i<items.Count;i++)

‎src/tests/test_interface.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,14 @@ def test_interface_collection_iteration():
136136
untyped_list.Add(elem)
137137
foreinuntyped_list:
138138
asserttype(e).__name__=="int"
139+
140+
141+
deftest_methods_of_Object_are_available():
142+
"""Test calling methods inherited from Object"""
143+
importSystem
144+
clrVal=System.Int32(100)
145+
i=System.IComparable(clrVal)
146+
asserti.Equals(clrVal)
147+
assertclrVal.GetHashCode()==i.GetHashCode()
148+
assertclrVal.GetType()==i.GetType()
149+
assertclrVal.ToString()==i.ToString()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp