8000 Ensure methods of Object are also available on interface objects by danabr · Pull Request #1284 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Ensure methods of Object are also available on interface objects #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ details about the cause of the failure
- Indexers can now be used with interface objects
- Fixed a bug where indexers could not be used if they were inherited
- Made it possible to use `__len__` also on `ICollection<>` interface objects
- Made it possible to call `ToString`, `GetHashCode`, and `GetType` on inteface objects

### Removed

Expand Down
11 changes: 11 additions & 0 deletions src/runtime/classmanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,17 @@ private static ClassInfo GetClassInfo(Type type)
}
}
}

// All interface implementations inherit from Object,
// but GetMembers don't return them either.
var objFlags = BindingFlags.Public | BindingFlags.Instance;
foreach (var mi in typeof(object).GetMembers(objFlags))
{
if (local[mi.Name] == null)
{
items.Add(mi);
}
}
}

for (i = 0; i < items.Count; i++)
Expand Down
11 changes: 11 additions & 0 deletions src/tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,14 @@ def test_interface_collection_iteration():
untyped_list.Add(elem)
for e in untyped_list:
assert type(e).__name__ == "int"


def test_methods_of_Object_are_available():
"""Test calling methods inherited from Object"""
import System
clrVal = System.Int32(100)
i = System.IComparable(clrVal)
assert i.Equals(clrVal)
assert clrVal.GetHashCode() == i.GetHashCode()
assert clrVal.GetType() == i.GetType()
assert clrVal.ToString() == i.ToString()
0