Exemplo n.º 1
0
 private static Expression Variable(IScopeVariable variable)
 {
     return(Expression.Convert(
                Expression.Property(
                    Expression.Constant(((IWeakReferencable)variable).WeakReference),
                    typeof(WeakReference).GetProperty("Target")
                    ),
                variable.GetType()
                ));
 }
Exemplo n.º 2
0
            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)
                           ));
            }
Exemplo n.º 3
0
            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)
                           ));
            }
Exemplo n.º 4
0
            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)
                           ));
            }
Exemplo n.º 5
0
 private static Expression Variable(IScopeVariable variable) {
     return Expression.Convert(
         Expression.Property(
             Expression.Constant(((IWeakReferencable)variable).WeakReference),
             typeof(WeakReference).GetProperty("Target")
         ), 
         variable.GetType()
     );
 }