Skip to content

Commit 94c94f4

Browse files
committed
Implements Implicit Conversion
1 parent 99e6021 commit 94c94f4

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
@@ -521,6 +521,20 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
521521
return ToManagedValue(value, underlyingType, out result, setError);
522522
}
523523

524+
var opImplicit = obType.GetMethod("op_Implicit", new[] { obType });
525+
if (opImplicit != null)
526+
{
527+
if (ToManagedValue(value, opImplicit.ReturnType, out result, setError))
528+
{
529+
opImplicit = obType.GetMethod("op_Implicit", new[] { result.GetType() });
530+
if (opImplicit != null)
531+
{
532+
result = opImplicit.Invoke(null, new[] { result });
533+
}
534+
return opImplicit != null;
535+
}
536+
}
537+
524538
return ToPrimitive(value, obType, out result, setError);
525539
}
526540

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)