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

Commitf1df348

Browse files
committed
Try to guess the correct element type from an enumerator, use in conversion
1 parent8df73d3 commitf1df348

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

‎src/runtime/converter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ internal static IntPtr ToPython(object value, Type type)
155155
// type is. we'd rather have the object bound to the actual
156156
// implementing class.
157157

158-
type=value.GetType();
158+
type=type??value.GetType();
159159

160160
TypeCodetc=Type.GetTypeCode(type);
161161

‎src/runtime/iterator.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usingSystem.Linq;
12
usingSystem;
23
usingSystem.Collections;
34

@@ -10,10 +11,18 @@ namespace Python.Runtime
1011
internalclassIterator:ExtensionType
1112
{
1213
privateIEnumeratoriter;
14+
privateTypetype;
1315

1416
publicIterator(IEnumeratore)
1517
{
1618
iter=e;
19+
20+
vargenericType=e.GetType().GetInterfaces().FirstOrDefault(
21+
x=>x.IsGenericType&&
22+
x.GetGenericTypeDefinition()==typeof(System.Collections.Generic.IEnumerator<>)
23+
);
24+
25+
type=genericType?.GetGenericArguments().FirstOrDefault();
1726
}
1827

1928

@@ -41,7 +50,7 @@ public static IntPtr tp_iternext(IntPtr ob)
4150
returnIntPtr.Zero;
4251
}
4352
objectitem=self.iter.Current;
44-
returnConverter.ToPythonImplicit(item);
53+
returnConverter.ToPython(item,type);
4554
}
4655

4756
publicstaticIntPtrtp_iter(IntPtrob)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp