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

AddedToPythonAs() extension method for explicit conversion using an arbitrary type#2419

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
joaompneves wants to merge13 commits intopythonnet:master
base:master
Choose a base branch
Loading
fromjoaompneves:support-specific-type-encoding
Open
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
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
PrevPrevious commit
NextNext commit
Add test description
  • Loading branch information
@joaompneves
joaompneves committedJul 18, 2024
commitcf8ff1f1d9e8514660b3bcc8ca79543fa49ee971
11 changes: 4 additions & 7 deletionssrc/embed_tests/Codecs.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -339,22 +339,19 @@ public void ExceptionDecoded()
Assert.AreEqual(TestExceptionMessage, error.Message);
}

[Test]
[Test(Description = "Tests encoding of an object that explicitly implements an interface.")]
public void ExplicitObjectInterfaceEncoded()
{
var obj = new ExplicitInterfaceObject();

// explicitly pass an interface (but not a generic type argument) to simulate a scenario where the type is not know at build time
// var encoder = new InterfaceEncoder(typeof(IObjectInterface));
// PyObjectConversions.RegisterEncoder(encoder);

using var scope = Py.CreateScope();
scope.Exec(@"
def call(obj):
return dir(obj)
");
var callFunc = scope.Get("call");
var members = callFunc.Invoke(obj.ToPythonAs(typeof(IObjectInterface))).As<string[]>();
// explicitly pass an interface (but not a generic type argument) to simulate a scenario where the type is not know at build time
var callArg = obj.ToPythonAs(typeof(IObjectInterface));
var members = callFunc.Invoke(callArg).As<string[]>();
CollectionAssert.Contains(members, nameof(IObjectInterface.MemberFromInterface));
CollectionAssert.DoesNotContain(members, nameof(ExplicitInterfaceObject.MemberFromObject));
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp