public DynamicMetaObject BindConvert(PythonConversionBinder binder) => ConvertWorker(binder, binder.Type, binder.ResultKind);
public DynamicMetaObject BindConvert(PythonConversionBinder binder) { return(ConvertWorker(binder, binder.Type, binder.ReturnType, binder.ResultKind)); }
public CompatConversionBinder(PythonConversionBinder binder, Type toType, bool isExplicit) : base(toType, isExplicit) { _binder = binder; }
private DynamicMetaObject TryPythonConversion(DynamicMetaObjectBinder conversion, Type type) { if (!type.IsEnum) { switch (type.GetTypeCode()) { case TypeCode.Object: if (type == typeof(Complex)) { return(MakeConvertRuleForCall(conversion, type, this, "__complex__", "ConvertToComplex", (() => MakeConvertRuleForCall(conversion, type, this, "__float__", "ConvertToFloat", (() => FallbackConvert(conversion)), (x) => Ast.Call(null, typeof(PythonOps).GetMethod(nameof(PythonOps.ConvertFloatToComplex)), x))), (x) => x)); } else if (type == typeof(BigInteger)) { if (!typeof(Extensible <BigInteger>).IsAssignableFrom(LimitType)) { return(MakeConvertRuleForCall(conversion, type, this, "__int__", "ConvertToInt", () => FallbackConvert(conversion), (x) => Ast.Call(null, typeof(PythonOps).GetMethod(nameof(PythonOps.ConvertIntToBigInt)), x))); // GH #52 } } else if (type == typeof(IEnumerable)) { return(PythonConversionBinder.ConvertToIEnumerable(conversion, Restrict(Value.GetType()))); } else if (type == typeof(IEnumerator)) { return(PythonConversionBinder.ConvertToIEnumerator(conversion, Restrict(Value.GetType()))); } else if (type.IsSubclassOf(typeof(Delegate))) { return(MakeDelegateTarget(conversion, type, Restrict(Value.GetType()))); } break; case TypeCode.Int32: return(MakeConvertRuleForCall(conversion, type, this, "__int__", "ConvertToInt", () => FallbackConvert(conversion), (x) => Ast.Call(null, typeof(PythonOps).GetMethod(nameof(PythonOps.ConvertIntToInt32)), x))); // GH #52 case TypeCode.Double: return(MakeConvertRuleForCall(conversion, type, this, "__float__", "ConvertToFloat")); case TypeCode.Boolean: return(PythonProtocol.ConvertToBool( conversion, this )); case TypeCode.String: if (!typeof(Extensible <string>).IsAssignableFrom(LimitType)) { return(MakeConvertRuleForCall(conversion, type, this, "__str__", "ConvertToString")); } break; } } return(null); }