8000 Method overload with decimal parameter accepts non-decimal numbers by AlexCatarino · Pull Request #10 · QuantConnect/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Method overload with decimal parameter accepts non-decimal numbers #10

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 14 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Implements Implicit Conversion
  • Loading branch information
AlexCatarino committed Mar 12, 2018
commit 2465ae56c6bf7efebfb8a7f11c10a82b7c1a5e6d
14 changes: 14 additions & 0 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,20 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
return ToManagedValue(value, underlyingType, out result, setError);
}

var opImplicit = obType.GetMethod("op_Implicit", new[] { obType });
if (opImplicit != null)
{
if (ToManagedValue(value, opImplicit.ReturnType, out result, setError))
{
opImplicit = obType.GetMethod("op_Implicit", new[] { result.GetType() });
if (opImplicit != null)
{
result = opImplicit.Invoke(null, new[] { result });
}
return opImplicit != null;
}
}

return ToPrimitive(value, obType, out result, setError);
}

Expand Down
7 changes: 7 additions & 0 deletions src/runtime/methodbinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
typematch = true;
clrtype = pi[n].ParameterType;
}
// this takes care of implicit conversions
var opImplicit = pi[n].ParameterType.GetMethod("op_Implicit", new[] { clrtype });
if (opImplicit != null)
{
typematch = opImplicit.ReturnType == pi[n].ParameterType;
clrtype = pi[n].ParameterType;
}
}
Runtime.XDecref(pyoptype);
if (!typematch)
Expand Down
0