public override DynamicMetaObject BindConvert(ConvertBinder/*!*/ conversion) { PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "BuiltinFunc Convert " + conversion.Type); PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "BuiltinFunc Convert"); if (conversion.Type.IsSubclassOf(typeof(Delegate))) { return MakeDelegateTarget(conversion, conversion.Type, Restrict(typeof(BuiltinFunction))); } return conversion.FallbackConvert(this); }
public override DynamicMetaObject/*!*/ BindConvert(ConvertBinder/*!*/ conversion) { if (conversion.Type.IsSubclassOf(typeof(Delegate))) { return MakeDelegateTarget(conversion, conversion.Type, Restrict(typeof(PythonFunction))); } return conversion.FallbackConvert(this); }
public override DynamicMetaObject BindConvert(ConvertBinder binder) { return(IsOverridden(nameof(DynamicProxy <T> .TryConvert)) ? CallMethodWithResult(nameof(DynamicProxy <T> .TryConvert), binder, NoArgs, e => binder.FallbackConvert(this, e)) : base.BindConvert(binder)); }
public override DynamicMetaObject BindConvert(ConvertBinder binder) { return(IsOverridden("TryConvert") ? CallMethodWithResult("TryConvert", binder, NoArgs, e => binder.FallbackConvert(this, e)) : base.BindConvert(binder)); }
/// <summary> /// Performs the binding of the dynamic conversion operation. /// </summary> /// <param name="binder">An instance of the <see cref="ConvertBinder"/> that represents the details of the dynamic operation.</param> /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns> public virtual DynamicMetaObject BindConvert(ConvertBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return binder.FallbackConvert(this); }
public override DynamicMetaObject BindConvert(ConvertBinder binder) { if (IsOverridden("TryConvert")) { return CallMethodWithResult("TryConvert", binder, NoArgs, (e) => binder.FallbackConvert(this, e)); } return base.BindConvert(binder); }
public override DynamicMetaObject BindConvert(ConvertBinder binder) { if (!this.IsOverridden("TryConvert")) { return(base.BindConvert(binder)); } return(this.CallMethodWithResult("TryConvert", binder, DynamicProxyMetaObject <T> .NoArgs, (DynamicMetaObject e) => binder.FallbackConvert(this, e), null)); }
private DynamicMetaObject/*!*/ MakeConvertRuleForCall(ConvertBinder/*!*/ convertToAction, DynamicMetaObject/*!*/ self, SymbolId symbolId, string returner) { PythonType pt = ((IPythonObject)self.Value).PythonType; PythonTypeSlot pts; CodeContext context = BinderState.GetBinderState(convertToAction).Context; if (pt.TryResolveSlot(context, symbolId, out pts) && !IsBuiltinConversion(context, pts, symbolId, pt)) { ParameterExpression tmp = Ast.Variable(typeof(object), "func"); Expression callExpr = Ast.Call( PythonOps.GetConversionHelper(returner, GetResultKind(convertToAction)), Ast.Dynamic( new PythonInvokeBinder( BinderState.GetBinderState(convertToAction), new CallSignature(0) ), typeof(object), BinderState.GetCodeContext(convertToAction), tmp ) ); if (typeof(Extensible<>).MakeGenericType(convertToAction.Type).IsAssignableFrom(self.GetLimitType())) { // if we're doing a conversion to the underlying type and we're an // Extensible<T> of that type: // if an extensible type returns it's self in a conversion, then we need // to actually return the underlying value. If an extensible just keeps // returning more instances of it's self a stack overflow occurs - both // behaviors match CPython. callExpr = AstUtils.Convert(AddExtensibleSelfCheck(convertToAction, self, callExpr), typeof(object)); } return new DynamicMetaObject( Ast.Block( new ParameterExpression[] { tmp }, Ast.Condition( BindingHelpers.CheckTypeVersion( self.Expression, pt.Version ), Ast.Condition( MakeTryGetTypeMember( BinderState.GetBinderState(convertToAction), pts, self.Expression, tmp ), callExpr, AstUtils.Convert( ConversionFallback(convertToAction), typeof(object) ) ), convertToAction.Defer(this).Expression ) ), self.Restrict(self.GetRuntimeType()).Restrictions ); } return convertToAction.FallbackConvert(this); }
/// <summary> /// Performs the binding of the dynamic conversion operation. /// </summary> /// <param name="binder">An instance of the <see cref="ConvertBinder"/> that represents the details of the dynamic operation.</param> /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns> public virtual DynamicMetaObject BindConvert(ConvertBinder binder) { ContractUtils.RequiresNotNull(binder, "binder"); return(binder.FallbackConvert(this)); }
public override DynamicMetaObject BindConvert(ConvertBinder binder) { return(binder.FallbackConvert(_baseMetaObject, AddTypeRestrictions(_metaObject.BindConvert(binder)))); }
private DynamicMetaObject/*!*/ MakeConvertToBool(ConvertBinder/*!*/ conversion) { DynamicMetaObject self = Restrict(typeof(OldInstance)); ParameterExpression tmp = Ast.Variable(typeof(bool?), "tmp"); DynamicMetaObject fallback = conversion.FallbackConvert(this); Type resType = BindingHelpers.GetCompatibleType(typeof(bool), fallback.Expression.Type); return new DynamicMetaObject( Ast.Block( new ParameterExpression[] { tmp }, Ast.Condition( Ast.NotEqual( Ast.Assign( tmp, Ast.Call( typeof(PythonOps).GetMethod("OldInstanceConvertToBoolNonThrowing"), AstUtils.Constant(BinderState.GetBinderState(conversion).Context), self.Expression ) ), AstUtils.Constant(null) ), AstUtils.Convert(tmp, resType), AstUtils.Convert(fallback.Expression, resType) ) ), self.Restrictions ); }
private DynamicMetaObject/*!*/ MakeConvertToCommon(ConvertBinder/*!*/ conversion, SymbolId symbolId) { ParameterExpression tmp = Ast.Variable(typeof(object), "convertResult"); DynamicMetaObject self = Restrict(typeof(OldInstance)); return new DynamicMetaObject( Ast.Block( new ParameterExpression[] { tmp }, Ast.Condition( MakeOneConvert(conversion, self, symbolId, tmp), tmp, AstUtils.Convert( conversion.FallbackConvert(this).Expression, typeof(object) ) ) ), self.Restrictions ); }
private DynamicMetaObject/*!*/ MakeConvertToIEnumerable(ConvertBinder/*!*/ conversion, Type genericType) { ParameterExpression tmp = Ast.Variable(conversion.Type, "res"); DynamicMetaObject self = Restrict(typeof(OldInstance)); return new DynamicMetaObject( Ast.Block( new ParameterExpression[] { tmp }, Ast.Condition( Ast.NotEqual( Ast.Assign( tmp, Ast.Call( typeof(PythonOps).GetMethod("OldInstanceConvertToIEnumerableOfTNonThrowing").MakeGenericMethod(genericType), AstUtils.Constant(BinderState.GetBinderState(conversion).Context), self.Expression ) ), AstUtils.Constant(null) ), tmp, AstUtils.Convert( AstUtils.Convert( conversion.FallbackConvert(this).Expression, typeof(object) ), conversion.Type ) ) ), self.Restrictions ); }