8000 Implements Implicit Conversion · QuantConnect/pythonnet@78b644b · GitHub
[go: up one dir, main page]

Skip to content

Commit 78b644b

Browse files
committed
Implements Implicit Conversion
1 parent d0cd40f commit 78b644b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/runtime/converter.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,20 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
513513
return ToManagedValue(value, underlyingType, out result, setError);
514514
}
515515

516+
var opImplicit = obType.GetMethod("op_Implicit", new[] { obType });
517+
if (opImplicit != null)
518+
{
519+
if (ToManagedValue(value, opImplicit.ReturnType, out result, setError))
520+
{
521+
opImplicit = obType.GetMethod("op_Implicit", new[] { result.GetType() });
522+
if (opImplicit != null)
523+
{
524+
result = opImplicit.Invoke(null, new[] { result });
525+
}
526+
return opImplicit != null;
527+
}
528+
}
529+
516530
return ToPrimitive(value, obType, out result, setError);
517531
}
518532

src/runtime/methodbinder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
408408
typematch = true;
409409
clrtype = pi[n].ParameterType;
410410
}
411+
// this takes care of implicit conversions
412+
var opImplicit = pi[n].ParameterType.GetMethod("op_Implicit", new[] { clrtype });
413+
if (opImplicit != null)
414+
{
415+
typematch = opImplicit.ReturnType == pi[n].ParameterType;
416+
clrtype = pi[n].ParameterType;
417+
}
411418
}
412419
Runtime.XDecref(pyoptype);
413420
if (!typematch)

0 commit comments

Comments
 (0)
0