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


C# ProxyGenerationOptions.AddMixinInstance方法代码示例

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


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

示例1: GetFieldInterceptionProxy

		/// <summary>
		/// Returns a proxy capable of field interception.
		/// </summary>
		/// <returns></returns>
        public override object GetFieldInterceptionProxy() 
        {
            var proxyGenerationOptions = new ProxyGenerationOptions();
            var interceptor = new LazyFieldInterceptor();
            proxyGenerationOptions.AddMixinInstance(interceptor);
            return ProxyGenerator.CreateClassProxy(PersistentClass, proxyGenerationOptions, interceptor);
        }
开发者ID:oillio,项目名称:Castle.ActiveRecord,代码行数:11,代码来源:ProxyFactory.cs

示例2: Mixin_methods_should_be_forwarded_to_target_if_implements_mixin_interface

		public void Mixin_methods_should_be_forwarded_to_target_if_implements_mixin_interface()
		{
			var options = new ProxyGenerationOptions();
			options.AddMixinInstance(new Two());
			var proxy = generator.CreateInterfaceProxyWithTargetInterface(typeof(IOne),
			                                                              new OneTwo(),
			                                                              options);
			var result = (proxy as ITwo).TwoMethod();
			Assert.AreEqual(2, result);
		}
开发者ID:gitter-badger,项目名称:Core-8,代码行数:10,代码来源:InterfaceProxyWithTargetInterfaceTestCase.cs

示例3: Invocation_should_be_IChangeInvocationTarget_for_Mixin_methods

		public void Invocation_should_be_IChangeInvocationTarget_for_Mixin_methods()
		{
			var options = new ProxyGenerationOptions();
			options.AddMixinInstance(new Two());
			var interceptor = new ChangeTargetInterceptor(new OneTwo());
			var proxy = generator.CreateInterfaceProxyWithTargetInterface(typeof(IOne),
			                                                              new One(),
			                                                              options,
			                                                              interceptor);

			var result = (proxy as ITwo).TwoMethod();

			Assert.AreEqual(2, result);
		}
开发者ID:JulianBirch,项目名称:Castle.Core,代码行数:14,代码来源:InterfaceProxyWithTargetInterfaceTestCase.cs

示例4: TwoMixinsWithSameInterface

		public void TwoMixinsWithSameInterface()
		{
			ProxyGenerationOptions options = new ProxyGenerationOptions();
			SimpleMixin mixin1 = new SimpleMixin();
			OtherMixinImplementingISimpleMixin mixin2 = new OtherMixinImplementingISimpleMixin();
			options.AddMixinInstance(mixin1);
			options.AddMixinInstance(mixin2);

			StandardInterceptor interceptor = new StandardInterceptor();

			Assert.Throws<InvalidMixinConfigurationException>(() =>
				generator.CreateClassProxy(typeof(SimpleClass), options, interceptor)
			);
		}
开发者ID:elevine,项目名称:Core,代码行数:14,代码来源:MixinTestCase.cs

示例5: TestTypeCachingWithMultipleMixins

		public void TestTypeCachingWithMultipleMixins()
		{
			ProxyGenerationOptions options = new ProxyGenerationOptions();
			SimpleMixin mixin_instance1 = new SimpleMixin();
			ComplexMixin mixin_instance2 = new ComplexMixin();
			options.AddMixinInstance(mixin_instance1);
			options.AddMixinInstance(mixin_instance2);

			AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor();

			object proxy1 = generator.CreateClassProxy(typeof (SimpleClass), options, interceptor);

			options = new ProxyGenerationOptions();
			mixin_instance1 = new SimpleMixin();
			mixin_instance2 = new ComplexMixin();
			options.AddMixinInstance(mixin_instance2);
			options.AddMixinInstance(mixin_instance1);

			interceptor = new AssertInvocationInterceptor();

			object proxy2 = generator.CreateClassProxy(typeof (SimpleClass), options, interceptor);

			Assert.IsTrue(proxy1.GetType().Equals(proxy2.GetType()));
		}
开发者ID:elevine,项目名称:Core,代码行数:24,代码来源:MixinTestCase.cs

示例6: MixinImplementingMoreThanOneInterface

		public void MixinImplementingMoreThanOneInterface()
		{
			ProxyGenerationOptions proxyGenerationOptions = new ProxyGenerationOptions();

			ComplexMixin mixin_instance = new ComplexMixin();
			proxyGenerationOptions.AddMixinInstance(mixin_instance);

			AssertInvocationInterceptor interceptor = new AssertInvocationInterceptor();

			object proxy = generator.CreateClassProxy(
				typeof (SimpleClass), proxyGenerationOptions, interceptor);

			Assert.IsNotNull(proxy);
			Assert.IsTrue(typeof (SimpleClass).IsAssignableFrom(proxy.GetType()));

			Assert.IsFalse(interceptor.Invoked);

			IThird inter3 = proxy as IThird;
			Assert.IsNotNull(inter3);
			inter3.DoThird();

			Assert.IsTrue(interceptor.Invoked);
			Assert.AreSame(proxy, interceptor.proxy);
			Assert.AreSame(mixin_instance, interceptor.mixin);

			ISecond inter2 = proxy as ISecond;
			Assert.IsNotNull(inter2);
			inter2.DoSecond();

			Assert.IsTrue(interceptor.Invoked);
			Assert.AreSame(proxy, interceptor.proxy);
			Assert.AreSame(mixin_instance, interceptor.mixin);

			IFirst inter1 = proxy as IFirst;
			Assert.IsNotNull(inter1);
			inter1.DoFirst();

			Assert.IsTrue(interceptor.Invoked);
			Assert.AreSame(proxy, interceptor.proxy);
			Assert.AreSame(mixin_instance, interceptor.mixin);
		}
开发者ID:elevine,项目名称:Core,代码行数:41,代码来源:MixinTestCase.cs

示例7: CanCreateSimpleMixinWithoutGettingExecutionEngineExceptionsOrBadImageExceptions

		public void CanCreateSimpleMixinWithoutGettingExecutionEngineExceptionsOrBadImageExceptions()
		{
			ProxyGenerationOptions proxyGenerationOptions = new ProxyGenerationOptions();
			proxyGenerationOptions.AddMixinInstance(new SimpleMixin());
			object proxy = generator.CreateClassProxy(
				typeof (object), proxyGenerationOptions, new AssertInvocationInterceptor());

			Assert.IsTrue(proxy is ISimpleMixin);

			((ISimpleMixin) proxy).DoSomething();
		}
开发者ID:elevine,项目名称:Core,代码行数:11,代码来源:MixinTestCase.cs

示例8: TwoMixinsWithSameInterface

		public void TwoMixinsWithSameInterface()
		{
			ProxyGenerationOptions options = new ProxyGenerationOptions();
			SimpleMixin mixin1 = new SimpleMixin();
			OtherMixinImplementingISimpleMixin mixin2 = new OtherMixinImplementingISimpleMixin();
			options.AddMixinInstance(mixin1);
			options.AddMixinInstance(mixin2);

			StandardInterceptor interceptor = new StandardInterceptor();
			generator.CreateClassProxy(typeof(SimpleClass), options, interceptor);
		}
开发者ID:AllEmpty,项目名称:Core,代码行数:11,代码来源:MixinTestCase.cs

示例9: Null_target_can_be_replaced

		public void Null_target_can_be_replaced()
		{
			var options = new ProxyGenerationOptions();
			options.AddMixinInstance(new Two());
			var interceptor = new ChangeTargetInterceptor(new OneTwo());
			var proxy = generator.CreateInterfaceProxyWithTargetInterface(typeof(IOne),
			                                                              default(object),
			                                                              options,
			                                                              interceptor);

			Assert.AreEqual(3, ((IOne) proxy).OneMethod());
		}
开发者ID:gitter-badger,项目名称:Core-8,代码行数:12,代码来源:InterfaceProxyWithTargetInterfaceTestCase.cs

示例10: Uses_The_Provided_Options

		public void Uses_The_Provided_Options()
		{
			var options = new ProxyGenerationOptions();
			options.AddMixinInstance(new SimpleMixin());

			var target = new SimpleClassWithProperty();
			var proxy = generator.CreateClassProxyWithTarget(target, options);

			Assert.IsInstanceOf(typeof(ISimpleMixin), proxy);
		}
开发者ID:gitter-badger,项目名称:Core-8,代码行数:10,代码来源:ClassProxyWithTargetTestCase.cs

示例11: MixIn

		private ProxyGenerationOptions MixIn(object mixin)
		{
			var options = new ProxyGenerationOptions();
			options.AddMixinInstance(mixin);
			return options;
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:6,代码来源:ProxyTargetAccessorHandlingTestCase.cs

示例12: ProxyGenerationOptionsRespectedOnDeserializationComplex

		public void ProxyGenerationOptionsRespectedOnDeserializationComplex ()
		{
			ProxyObjectReference.ResetScope ();

			MethodFilterHook hook = new MethodFilterHook ("get_Current");
			ProxyGenerationOptions options = new ProxyGenerationOptions (hook);
			options.AddMixinInstance (new SerializableMixin());
			options.Selector = new SerializableInterceptorSelector ();

			ComplexHolder holder = new ComplexHolder();
			holder.Type = typeof (MySerializableClass);
			holder.Element = generator.CreateClassProxy (typeof (MySerializableClass), new Type[0], options, new StandardInterceptor ());

			// check holder elements
			Assert.AreEqual (typeof (MySerializableClass), holder.Type);
			Assert.IsNotNull (holder.Element);
			Assert.IsTrue (holder.Element is MySerializableClass) ;
			Assert.AreNotEqual (typeof (MySerializableClass), holder.Element.GetType ());

			// check whether options were applied correctly
			Assert.AreEqual (holder.Element.GetType (), holder.Element.GetType ().GetMethod ("get_Current").DeclaringType);
			Assert.AreNotEqual (holder.Element.GetType (), holder.Element.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType);
			Assert.AreEqual (holder.Element.GetType ().BaseType, holder.Element.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType);
			ProxyGenerationOptions options2 = (ProxyGenerationOptions) holder.Element.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
			Assert.IsNotNull (Array.Find (options2.MixinsAsArray (), delegate (object o) { return o is SerializableMixin; }));
			Assert.IsNotNull (options2.Selector);

			ComplexHolder otherHolder = (ComplexHolder) SerializeAndDeserialize (holder);

			// check holder elements
			Assert.AreEqual (typeof (MySerializableClass), otherHolder.Type);
			Assert.IsNotNull (otherHolder.Element);
			Assert.IsTrue (otherHolder.Element is MySerializableClass);
			Assert.AreNotEqual(typeof (MySerializableClass), otherHolder.Element.GetType());

			// check whether options were applied correctly
			Assert.AreEqual (otherHolder.Element.GetType (), otherHolder.Element.GetType ().GetMethod ("get_Current").DeclaringType);
			Assert.AreNotEqual (otherHolder.Element.GetType (), otherHolder.Element.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType);
			Assert.AreEqual (otherHolder.Element.GetType ().BaseType, otherHolder.Element.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType);
			options2 = (ProxyGenerationOptions) otherHolder.Element.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
			Assert.IsNotNull (Array.Find (options2.MixinsAsArray (), delegate (object o) { return o is SerializableMixin; }));
			Assert.IsNotNull (options2.Selector);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:43,代码来源:SerializableClassTestCase.cs

示例13: MixinsAppliedOnDeserialization

		public void MixinsAppliedOnDeserialization ()
		{
			ProxyObjectReference.ResetScope ();

			ProxyGenerationOptions options = new ProxyGenerationOptions ();
			options.AddMixinInstance (new SerializableMixin ());

			MySerializableClass proxy = (MySerializableClass) generator.CreateClassProxy (
					typeof (MySerializableClass),
					new Type[0],
					options,
					new StandardInterceptor ());

			Assert.IsTrue (proxy is IMixedInterface);

			MySerializableClass otherProxy = (MySerializableClass) SerializeAndDeserialize (proxy);
			Assert.IsTrue (otherProxy is IMixedInterface);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:18,代码来源:SerializableClassTestCase.cs

示例14: ProxyGenerationOptionsRespectedOnDeserialization

		public void ProxyGenerationOptionsRespectedOnDeserialization ()
		{
			ProxyObjectReference.ResetScope();

			MethodFilterHook hook = new MethodFilterHook ("get_Current");
			ProxyGenerationOptions options = new ProxyGenerationOptions (hook);
			options.AddMixinInstance (new SerializableMixin());
			options.Selector = new SerializableInterceptorSelector ();

			MySerializableClass proxy = (MySerializableClass) generator.CreateClassProxy (
			    typeof (MySerializableClass),
			    new Type[0],
			    options,
			    new StandardInterceptor());

			Assert.AreEqual (proxy.GetType(), proxy.GetType().GetMethod ("get_Current").DeclaringType);
			Assert.AreNotEqual (proxy.GetType(), proxy.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType);
			Assert.AreEqual (proxy.GetType().BaseType, proxy.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType);
			ProxyGenerationOptions options2 = (ProxyGenerationOptions) proxy.GetType().GetField("proxyGenerationOptions").GetValue(null);
			Assert.IsNotNull (Array.Find (options2.MixinsAsArray (), delegate (object o) { return o is SerializableMixin; }));
			Assert.IsNotNull (options2.Selector);

			MySerializableClass otherProxy = (MySerializableClass) SerializeAndDeserialize (proxy);
			Assert.AreEqual (otherProxy.GetType(), otherProxy.GetType().GetMethod ("get_Current").DeclaringType);
			Assert.AreNotEqual (otherProxy.GetType(), otherProxy.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType);
			Assert.AreEqual (otherProxy.GetType().BaseType, otherProxy.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType);
			options2 = (ProxyGenerationOptions) otherProxy.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
			Assert.IsNotNull (Array.Find (options2.MixinsAsArray (), delegate (object o) { return o is SerializableMixin; }));
			Assert.IsNotNull (options2.Selector);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:30,代码来源:SerializableClassTestCase.cs

示例15: ProxyKnowsItsGenerationOptions

		public void ProxyKnowsItsGenerationOptions ()
		{
			MethodFilterHook hook = new MethodFilterHook (".*");
			ProxyGenerationOptions options = new ProxyGenerationOptions (hook);
			options.AddMixinInstance (new SerializableMixin ());

			object proxy = generator.CreateClassProxy (
					typeof (MySerializableClass),
					new Type[0],
					options,
					new StandardInterceptor ());

			FieldInfo field = proxy.GetType ().GetField ("proxyGenerationOptions");
			Assert.IsNotNull (field);
			Assert.AreSame (options, field.GetValue (proxy));

			base.Init ();

			proxy = generator.CreateInterfaceProxyWithoutTarget (typeof (IService), new StandardInterceptor ());
			field = proxy.GetType ().GetField ("proxyGenerationOptions");
			Assert.AreSame (ProxyGenerationOptions.Default, field.GetValue (proxy));

			base.Init ();

			proxy = generator.CreateInterfaceProxyWithTarget (typeof (IService), new ServiceImpl(), options, new StandardInterceptor ());
			field = proxy.GetType ().GetField ("proxyGenerationOptions");
			Assert.AreSame (options, field.GetValue (proxy));

			base.Init ();

			proxy = generator.CreateInterfaceProxyWithTargetInterface (typeof (IService), new ServiceImpl(), new StandardInterceptor ());
			field = proxy.GetType ().GetField ("proxyGenerationOptions");
			Assert.AreSame (ProxyGenerationOptions.Default, field.GetValue (proxy));
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:34,代码来源:SerializableClassTestCase.cs


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