private static Expression Variable(IScopeVariable variable) { return(Expression.Convert( Expression.Property( Expression.Constant(((IWeakReferencable)variable).WeakReference), typeof(WeakReference).GetProperty("Target") ), variable.GetType() )); }
public override DynamicMetaObject BindDeleteMember(DeleteMemberBinder binder) { IScopeVariable variable = Value.GetScopeVariable(binder.Name, binder.IgnoreCase); return(new DynamicMetaObject( Expression.Condition( Expression.Call( Variable(variable), variable.GetType().GetMethod("DeleteValue") ), Expression.Default(binder.ReturnType), binder.FallbackDeleteMember(this).Expression ), BindingRestrictions.GetInstanceRestriction(Expression, Value) )); }
public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value) { IScopeVariable variable = Value.GetScopeVariable(binder.Name, binder.IgnoreCase); var objExpression = ExpressionUtils.Convert(value.Expression, typeof(object)); return(new DynamicMetaObject( Expression.Block( Expression.Call( Variable(variable), variable.GetType().GetMethod("SetValue"), objExpression ), objExpression ), BindingRestrictions.GetInstanceRestriction(Expression, Value) )); }
private DynamicMetaObject DynamicTryGetValue(string name, bool ignoreCase, Expression fallback, Func <Expression, Expression> resultOp) { IScopeVariable variable = Value.GetScopeVariable(name, ignoreCase); var tmp = Expression.Parameter(typeof(object)); return(new DynamicMetaObject( Expression.Block( new[] { tmp }, Expression.Condition( Expression.Call( Variable(variable), variable.GetType().GetMethod("TryGetValue"), tmp ), ExpressionUtils.Convert(resultOp(tmp), typeof(object)), ExpressionUtils.Convert(fallback, typeof(object)) ) ), BindingRestrictions.GetInstanceRestriction(Expression, Value) )); }
private static Expression Variable(IScopeVariable variable) { return Expression.Convert( Expression.Property( Expression.Constant(((IWeakReferencable)variable).WeakReference), typeof(WeakReference).GetProperty("Target") ), variable.GetType() ); }