当前位置: 首页>>代码示例>>C#>>正文


C# ProxyFactory.AddIntroduction方法代码示例

本文整理汇总了C#中Spring.Aop.Framework.ProxyFactory.AddIntroduction方法的典型用法代码示例。如果您正苦于以下问题:C# ProxyFactory.AddIntroduction方法的具体用法?C# ProxyFactory.AddIntroduction怎么用?C# ProxyFactory.AddIntroduction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Spring.Aop.Framework.ProxyFactory的用法示例。


在下文中一共展示了ProxyFactory.AddIntroduction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetProxy

        private static Contact GetProxy()
        {
            Contact target = new Contact();
            target.FirstName = "Aleksandar";
            target.LastName = "Seovic";

            ProxyFactory pf = new ProxyFactory(target);
            pf.AddAdvisor(new ModificationAdvisor(target.GetType()));
            pf.AddIntroduction(new IsModifiedAdvisor());
            pf.ProxyTargetType = true;

            return (Contact)pf.GetProxy();
        }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:13,代码来源:Program.cs

示例2: TestIntroductionInterceptorWithDelegation

		public void TestIntroductionInterceptorWithDelegation()
		{
			TestObject raw = new TestObject();
			Assert.IsTrue(! (raw is ITimeStamped));
			ProxyFactory factory = new ProxyFactory(raw);
	
			ITimeStampedIntroduction ts = MockRepository.GenerateMock<ITimeStampedIntroduction>();
			ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP);

			DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
			factory.AddIntroduction(advisor);

			ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
			Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
		}
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:15,代码来源:DelegatingIntroductionInterceptorTests.cs

示例3: testIntroductionInterceptorWithDelegation

		public void testIntroductionInterceptorWithDelegation()
		{
			TestObject raw = new TestObject();
			Assert.IsTrue(! (raw is ITimeStamped));
			ProxyFactory factory = new ProxyFactory(raw);
	
			IDynamicMock tsControl = new DynamicMock(typeof(ITimeStampedIntroduction));
			ITimeStampedIntroduction ts = (ITimeStampedIntroduction) tsControl.Object;
			tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);

			DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
			factory.AddIntroduction(advisor);

			ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
			Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
	
			tsControl.Verify();
		}
开发者ID:fuadm,项目名称:spring-net,代码行数:18,代码来源:DelegatingIntroductionInterceptorTests.cs

示例4: TestIntroductionInterceptorWithSuperInterface

		public void TestIntroductionInterceptorWithSuperInterface()  
		{
			TestObject raw = new TestObject();
			Assert.IsTrue(! (raw is ITimeStamped));
			ProxyFactory factory = new ProxyFactory(raw);

            ISubTimeStamped ts = MockRepository.GenerateMock<ISubTimeStampedIntroduction>();
			ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP);

			factory.AddIntroduction(0, new DefaultIntroductionAdvisor(
				(ISubTimeStampedIntroduction)ts,
				typeof(ITimeStamped))
				);

			ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
			Assert.IsTrue(!(tsp is ISubTimeStamped));
			Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
		}
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:18,代码来源:DelegatingIntroductionInterceptorTests.cs

示例5: TestIntroductionInterceptorWithInterfaceHierarchy

		public void TestIntroductionInterceptorWithInterfaceHierarchy() 
		{
			TestObject raw = new TestObject();
			Assert.IsTrue(! (raw is ISubTimeStamped));
			ProxyFactory factory = new ProxyFactory(raw);

            ISubTimeStampedIntroduction ts = MockRepository.GenerateMock<ISubTimeStampedIntroduction>();
			ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP);

			DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
			// we must add introduction, not an advisor
			factory.AddIntroduction(advisor);

			object proxy = factory.GetProxy();
			ISubTimeStamped tsp = (ISubTimeStamped) proxy;
			Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
		}
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:17,代码来源:DelegatingIntroductionInterceptorTests.cs

示例6: TestAutomaticInterfaceRecognitionInDelegate

		public void TestAutomaticInterfaceRecognitionInDelegate() 
		{
			IIntroductionAdvisor ia = new DefaultIntroductionAdvisor(new Test(EXPECTED_TIMESTAMP));
		
			TestObject target = new TestObject();
			ProxyFactory pf = new ProxyFactory(target);
			pf.AddIntroduction(0, ia);

			ITimeStamped ts = (ITimeStamped) pf.GetProxy();
		
			Assert.IsTrue(ts.TimeStamp == EXPECTED_TIMESTAMP);
			((ITest) ts).Foo();
		
			int age = ((ITestObject) ts).Age;
		}
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:15,代码来源:DelegatingIntroductionInterceptorTests.cs

示例7: NestedProxiesDontInvokeSameAdviceOrIntroductionTwice

        public void NestedProxiesDontInvokeSameAdviceOrIntroductionTwice()
        {
            MultiProxyingTestClass testObj = new MultiProxyingTestClass();
            ProxyFactory pf1 = new ProxyFactory();
            pf1.Target = testObj;

            NopInterceptor di = new NopInterceptor();
            NopInterceptor diUnused = new NopInterceptor(1); // // make instance unique (see SPRNET-847)
            TestCountingIntroduction countingMixin = new TestCountingIntroduction();

            pf1.AddAdvice(diUnused);
            pf1.AddAdvisor(new DefaultPointcutAdvisor(di));
            pf1.AddIntroduction(new DefaultIntroductionAdvisor(countingMixin));

            object innerProxy = pf1.GetProxy();
            ProxyFactory pf2 = new ProxyFactory();
            pf2.Target = innerProxy;
            pf2.AddAdvice(diUnused);
            pf2.AddAdvisor(new DefaultPointcutAdvisor(di));
            pf2.AddIntroduction(new DefaultIntroductionAdvisor(countingMixin));

            object outerProxy = pf2.GetProxy();

            // any advice instance is invoked once only
            string result = ((IMultiProxyingTestInterface)outerProxy).TestMethod("arg");
            Assert.AreEqual(1, testObj.InvocationCounter);
            Assert.AreEqual("arg|arg", result);
            Assert.AreEqual(1, di.Count);

            // any introduction instance is invoked once only
            ((ICountingIntroduction)outerProxy).Inc();
            Assert.AreEqual(1, countingMixin.Counter);
        }
开发者ID:smnbss,项目名称:spring-net,代码行数:33,代码来源:ProxyFactoryTests.cs

示例8: GetsAllInterfaces

        public void GetsAllInterfaces()
        {
            // Extend to get new interface
            TestObjectSubclass raw = new TestObjectSubclass();
            ProxyFactory factory = new ProxyFactory(raw);
            Assert.AreEqual(8, factory.Interfaces.Length, "Found correct number of interfaces");
            //System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
            ITestObject tb = (ITestObject)factory.GetProxy();
            Assert.IsTrue(tb is IOther, "Picked up secondary interface");

            raw.Age = 25;
            Assert.IsTrue(tb.Age == raw.Age);

            DateTime t = new DateTime(2004, 8, 1);
            TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);

            Console.WriteLine(StringUtils.ArrayToDelimitedString(factory.Interfaces, "/"));

            //factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, typeof(ITimeStamped)));
            factory.AddIntroduction(
                new DefaultIntroductionAdvisor(ti, typeof(ITimeStamped))
                );

            Console.WriteLine(StringUtils.ArrayToDelimitedString(factory.Interfaces, "/"));

            ITimeStamped ts = (ITimeStamped)factory.GetProxy();
            Assert.IsTrue(ts.TimeStamp == t);
            // Shouldn't fail;
            ((IOther)ts).Absquatulate();
        }
开发者ID:smnbss,项目名称:spring-net,代码行数:30,代码来源:ProxyFactoryTests.cs

示例9: AddAndRemoveEventHandlerThroughIntroduction

 public void AddAndRemoveEventHandlerThroughIntroduction()
 {
     TestObject target = new TestObject();
     DoubleClickableIntroduction dci = new DoubleClickableIntroduction();
     DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(dci);
     CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice();
     target.Name = "SOME-NAME";
     ProxyFactory pf = new ProxyFactory(target);
     pf.AddIntroduction(advisor);
     pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice));
     object proxy = pf.GetProxy();
     ITestObject to = proxy as ITestObject;
     Assert.IsNotNull(to);
     Assert.AreEqual("SOME-NAME", to.Name);
     IDoubleClickable doubleClickable = proxy as IDoubleClickable;
     // add event handler through introduction
     doubleClickable.DoubleClick += new EventHandler(OnClick);
     OnClickWasCalled = false;
     doubleClickable.FireDoubleClickEvent();
     Assert.IsTrue(OnClickWasCalled);
     Assert.AreEqual(3, countingBeforeAdvice.GetCalls());
     // remove event handler through introduction
     doubleClickable.DoubleClick -= new EventHandler(OnClick);
     OnClickWasCalled = false;
     doubleClickable.FireDoubleClickEvent();
     Assert.IsFalse(OnClickWasCalled);
     Assert.AreEqual(5, countingBeforeAdvice.GetCalls());
 }
开发者ID:smnbss,项目名称:spring-net,代码行数:28,代码来源:ProxyFactoryTests.cs

示例10: GetRequestHandler

        private IRequestHandler GetRequestHandler()
        {
            if (this.requestHandler == null)
            {
                ProxyFactory proxyFactory = new ProxyFactory(this);
                proxyFactory.AddInterface(typeof(IRequestHandler));
                proxyFactory.AddIntroduction(new DefaultIntroductionAdvisor(new HttpRequestHandler()));
                proxyFactory.ProxyTargetType = true;
                this.requestHandler = proxyFactory.GetProxy() as IRequestHandler;
            }

            return this.requestHandler;
        }
开发者ID:TatumAndBell,项目名称:RapidWebDev-Enterprise-CMS,代码行数:13,代码来源:DynamicPageDataToHtmlHandler.cs

示例11: testIntroductionInterceptorWithInterfaceHierarchy

		public void testIntroductionInterceptorWithInterfaceHierarchy() 
		{
			TestObject raw = new TestObject();
			Assert.IsTrue(! (raw is ISubTimeStamped));
			ProxyFactory factory = new ProxyFactory(raw);

			IDynamicMock tsControl = new DynamicMock(typeof(ISubTimeStampedIntroduction));
			ISubTimeStampedIntroduction ts = (ISubTimeStampedIntroduction) tsControl.Object;
			tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);

			DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
			// we must add introduction, not an advisor
			factory.AddIntroduction(advisor);

			object proxy = factory.GetProxy();
			ISubTimeStamped tsp = (ISubTimeStamped) proxy;
			Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);

			tsControl.Verify();
		}
开发者ID:fuadm,项目名称:spring-net,代码行数:20,代码来源:DelegatingIntroductionInterceptorTests.cs

示例12: CreateProxyFactory

        /// <summary>
        /// Create an AOP proxy for the given object.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="objectName">The name of the object.</param>
        /// <returns>The AOP Proxy for the object.</returns>
        protected virtual ProxyFactory CreateProxyFactory(Type objectType, string objectName)
        {
            ProxyFactory proxyFactory = new ProxyFactory();
            proxyFactory.ProxyTargetAttributes = this.ProxyTargetAttributes;
            proxyFactory.TargetSource = new InheritanceBasedAopTargetSource(objectType);
            if (!ProxyInterfaces)
            {
                proxyFactory.Interfaces = Type.EmptyTypes;
            }

            IAdvisor[] advisors = ResolveInterceptorNames();
            foreach (IAdvisor advisor in advisors)
            {
                if (advisor is IIntroductionAdvisor)
                {
                    proxyFactory.AddIntroduction((IIntroductionAdvisor)advisor);
                }
                else
                {
                    proxyFactory.AddAdvisor(advisor);
                }
            }

            return proxyFactory;
        }
开发者ID:smnbss,项目名称:spring-net,代码行数:31,代码来源:InheritanceBasedAopConfigurer.cs


注:本文中的Spring.Aop.Framework.ProxyFactory.AddIntroduction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。