示例#1
0
        static void Main()
        {
            Console.WriteLine("Testing first implementation");
            dynamic x = new Rumpelstiltskin("Hermione");
            x.Harry();
            x.Ron();
            x.Hermione();

            Console.WriteLine("Testing alternative implementation");
            // Now check the alternative implementation
            x = new Rumpelstiltskin("Ron");
            x.Harry();
            x.Ron();
            x.Hermione();
        }
        static void Main()
        {
            Console.WriteLine("Testing first implementation");
            dynamic x = new Rumpelstiltskin("Hermione");

            x.Harry();
            x.Ron();
            x.Hermione();

            Console.WriteLine("Testing alternative implementation");
            // Now check the alternative implementation
            x = new Rumpelstiltskin("Ron");
            x.Harry();
            x.Ron();
            x.Hermione();
        }
示例#3
0
            public override DynamicMetaObject BindInvokeMember
                (InvokeMemberBinder binder, DynamicMetaObject[] args)
            {
                Rumpelstiltskin targetObject = (Rumpelstiltskin)base.Value;
                Expression      self         = Expression.Convert(base.Expression,
                                                                  typeof(Rumpelstiltskin));

                Expression targetBehavior;

                if (binder.Name == targetObject.name)
                {
                    targetBehavior = Expression.Call(self, RightGuessMethod);
                }
                else
                {
                    targetBehavior = Expression.Call(self, WrongGuessMethod,
                                                     Expression.Constant(binder.Name));
                }

                var restrictions = BindingRestrictions.GetInstanceRestriction
                                       (self, targetObject);

                return(new DynamicMetaObject(targetBehavior, restrictions));
            }
示例#4
0
 internal MetaRumpelstiltskin(Expression expression, Rumpelstiltskin creator)
     : base(expression, BindingRestrictions.Empty, creator)
 {
 }
示例#5
0
 internal MetaRumpelstiltskin
     (Expression expression, Rumpelstiltskin creator)
     : base(expression, BindingRestrictions.Empty, creator)
 {
 }