public PersonBeanProxy(IPersonBean person, bool owner)
 {
     if (owner)
     {
         invocationHandler = new OwnerInvocationHandler(person);
     }
     else
     {
         invocationHandler = new NonOwnerInvocationHandler(person);
     }
 }
Exemplo n.º 2
0
 public OwnerInvocationHandler(IPersonBean person)
 {
     this.person = person;
 }
Exemplo n.º 3
0
 public static IPersonBean Create(IPersonBean personBean)
 {
     return((IPersonBean) new OwnerInvocationHandler(personBean).GetTransparentProxy());
 }
Exemplo n.º 4
0
 private OwnerInvocationHandler(IPersonBean personBean)
     : base(typeof(IPersonBean))
 {
     _personBean = personBean;
 }
        public static void Run()
        {
            IPersonBean joe = new PersonBean()
            {
                Name = "Joe", Gender = "Male", Interests = "Skiing", HotOrNot = 10
            };
            IPersonBean blow = new PersonBean()
            {
                Name = "Blow", Gender = "Unknown", Interests = "Farting around", HotOrNot = 1
            };

            IPersonBean ownerProxy = OwnerInvocationHandler <IPersonBean> .Create(joe);

            Console.WriteLine("Name is " + ownerProxy.Name);
            Console.WriteLine("Interests were " + ownerProxy.Interests);
            ownerProxy.Interests = "Mountain Climbing";
            Console.WriteLine("Interests set from owner proxy. They are now " + ownerProxy.Interests);
            try
            {
                ownerProxy.HotOrNot = 10;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Rating is " + ownerProxy.HotOrNot);
            Console.WriteLine(ownerProxy.Post());
            try
            {
                ownerProxy.Poke();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            IPersonBean nonOwnerProxy = NonOwnerInvocationHandler <IPersonBean> .Create(blow);

            Console.WriteLine("Name is " + nonOwnerProxy.Name);
            Console.WriteLine("Interests were " + nonOwnerProxy.Interests);
            try
            {
                nonOwnerProxy.Interests = "Mountain Climbing";
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Rating is " + nonOwnerProxy.HotOrNot);
            nonOwnerProxy.HotOrNot = 10;
            Console.WriteLine("Rating is now " + nonOwnerProxy.HotOrNot);
            try
            {
                Console.WriteLine(nonOwnerProxy.Post());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            nonOwnerProxy.Poke();
        }