• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DynamicProxy.ProxyGenerationOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ProxyGenerationOptions类属于Castle.DynamicProxy命名空间,在下文中一共展示了ProxyGenerationOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Proceed

        public override void Proceed()
        {
            var expectation = stubMessageBus.GetExpectationFor(Request.GetType());

            if (expectation == null)
            {
                var response = (Response)Activator.CreateInstance(Request.GetResponseType());
                response.CorrelationGuid = Request.CorrelationGuid;
                Response = GetSerializedVersion(response);
            }
            else
            {
                Response = GetSerializedVersion(expectation.Execute(Request));
            }

            if(Request.IsSideEffectFree)
            {
                try
                {
                    var options = new ProxyGenerationOptions(new NonVirtualCheckProxyGenerationHook());
                    var proxyGen = new ProxyGenerator();
                    proxyGen.CreateClassProxy(Request.GetResponseType(), options);
                }
                catch (Exception ex)
                {
                    throw new ColomboTestSupportException(string.Format("Response {0} cannot be proxied, probably because one or several of its members are not virtual.", Request.GetResponseType()), ex);
                }
            }
        }
开发者ID:julienblin,项目名称:Colombo,代码行数:29,代码来源:StubRequestHandleInvocation.cs


示例2: Decorate

        /// <summary>
        /// Decoration request
        /// </summary>
        /// <param name="context">Context info</param>
        /// <remarks>do not have to decorate, but may if it wants to. sorta..</remarks>
        public void Decorate(DecoratorContext context)
        {
            if (!CanDecorate(context))
                return;

            var options = new ProxyGenerationOptions();

            var services = context.Services;
            if (IgnoreClassAsService && services.Length > 1)
                services = services.Where(x => !x.IsClass).ToArray();

            var generator = new ProxyGenerator();
            if (services.Any(x => x.IsClass))
            {
                if (services.Length > 1)
                    throw new InvalidOperationException(
                        "A class that register itself as a service may not also be registered with interfaces. See the remarks in the IgnoreClassAsService property.");

                var clazz = context.Services.Single(x => x.IsClass);
                context.Instance = generator.CreateClassProxyWithTarget(clazz, context.Instance,
                                                                        CreateInterceptor(context));
            }
            else
            {
                var others = services.Where(x => x.IsInterface).Skip(1);
                var first = services.First();
                context.Instance = generator.CreateInterfaceProxyWithTarget
                    (first, others.ToArray(), context.Instance,
                     CreateInterceptor(context));
            }

        }
开发者ID:hallco978,项目名称:Griffin.Container,代码行数:37,代码来源:CastleDecorator.cs


示例3: Generate

		public object Generate(IProxyBuilder builder, ProxyGenerationOptions options, IInterceptor[] interceptors)
		{
			var type = GetProxyType(builder);
			var instance = GetProxyInstance(type,interceptors);
			var method = GetInvokeDelegate(instance);
			return method;
		}
开发者ID:gschuager,项目名称:Castle.Windsor,代码行数:7,代码来源:DelegateProxyFactory.cs


示例4: GenerateProxy

        private static ProxyGeneratorResult GenerateProxy(
            Type typeOfProxy,
            ProxyGenerationOptions options,
            IEnumerable<Type> additionalInterfacesToImplement,
            IEnumerable<object> argumentsForConstructor,
            IFakeCallProcessorProvider fakeCallProcessorProvider)
        {
            Guard.AgainstNull(typeOfProxy, nameof(typeOfProxy));
            Guard.AgainstNull(additionalInterfacesToImplement, nameof(additionalInterfacesToImplement));
            Guard.AgainstNull(fakeCallProcessorProvider, nameof(fakeCallProcessorProvider));

            if (typeOfProxy.GetTypeInfo().IsValueType)
            {
                return GetProxyResultForValueType(typeOfProxy);
            }

            if (typeOfProxy.GetTypeInfo().IsSealed)
            {
                return new ProxyGeneratorResult(DynamicProxyResources.ProxyIsSealedTypeMessage.FormatInvariant(typeOfProxy));
            }

            GuardAgainstConstructorArgumentsForInterfaceType(typeOfProxy, argumentsForConstructor);

            return CreateProxyGeneratorResult(typeOfProxy, options, additionalInterfacesToImplement, argumentsForConstructor, fakeCallProcessorProvider);
        }
开发者ID:bman61,项目名称:FakeItEasy,代码行数:25,代码来源:CastleDynamicProxyGenerator.cs


示例5: CanCreateMixinWithClassInterceptors

        public void CanCreateMixinWithClassInterceptors()
        {
            var options = new ProxyGenerationOptions();
            options.AddMixinInstance(new Dictionary<int, int>());

            var builder = new ContainerBuilder();
            builder.RegisterType<C>().EnableClassInterceptors(options);
            builder.RegisterType<AddOneInterceptor>();
            builder.RegisterType<AddTenInterceptor>();
            var container = builder.Build();
            var i = 10;
            var cpt = container.Resolve<C>(TypedParameter.From(i));

            var dict = cpt as IDictionary<int, int>;

            Assert.NotNull(dict);

            dict.Add(1, 2);

            Assert.Equal(2, dict[1]);

            dict.Clear();

            Assert.Empty(dict);
        }
开发者ID:jango2015,项目名称:Autofac.Extras.DynamicProxy,代码行数:25,代码来源:ClassInterceptorsWithOptionsFixture.cs


示例6: TrySetActionInvoker

        internal static IController TrySetActionInvoker(this IController iController, IGlimpseLogger logger)
        {
            var controller = iController as Controller;
            if (controller == null)
            {
                //TODO: Add Logging
                return iController;
            }

            var actionInvoker = controller.ActionInvoker;

            if (actionInvoker.CanSupportDynamicProxy(logger))
            {
                var proxyConfig = new Dictionary<string, IInterceptor>
                                      {
                                          {"GetFilters", new GetFiltersInterceptor()},
                                          {"InvokeActionResult", new InvokeActionResultInterceptor()},
                                          {"InvokeActionMethod",new InvokeActionMethodInterceptor()}
                                      };

                var proxyGenerator = new ProxyGenerator();
                var proxyGenOptions = new ProxyGenerationOptions(new SimpleProxyGenerationHook(logger, proxyConfig.Keys.ToArray())) { Selector = new SimpleInterceptorSelector(proxyConfig) };
                var newInvoker = (ControllerActionInvoker)proxyGenerator.CreateClassProxy(actionInvoker.GetType(), proxyGenOptions, proxyConfig.Values.ToArray());
                controller.ActionInvoker = newInvoker;
            }

            return controller;
        }
开发者ID:nagor,项目名称:Glimpse,代码行数:28,代码来源:ControllerExtensions.cs


示例7: GetFieldInterceptionProxy

        public override object GetFieldInterceptionProxy()
		{
			var proxyGenerationOptions = new ProxyGenerationOptions();
			var interceptor = new LazyFieldInterceptor();
			proxyGenerationOptions.AddMixinInstance(interceptor);
			return ProxyGenerator.CreateClassProxy(PersistentClass, proxyGenerationOptions, interceptor);
		}
开发者ID:modulexcite,项目名称:framework-1,代码行数:7,代码来源:ProxyFactory.cs


示例8: Register

        public void Register(ContainerBuilder builder)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            ProxyGenerationOptions ProxyOption = new ProxyGenerationOptions()
            {
                Selector = new InterceptorSelector()
            };
            //注册所有服务
            builder.RegisterAssemblyTypes(assembly)
               .Where(type => type.FullName.EndsWith("ApplicationService") && type.IsClass)
               .AsImplementedInterfaces()
               .EnableInterfaceInterceptors(ProxyOption)
               ;//.InterceptedBy(typeof(MethodInvacationValidateInterceptor), typeof(UnitOfWorkInterceptor));

            //注册DbContext
            builder.RegisterType<SampleEntities>().As<DbContext>();

            //注册所有泛型仓储
            var finder = new WebAppTypeFinder();
            var allEntityTypes = finder.FindClassOfType(typeof(IEntity));
            foreach (var entityType in allEntityTypes)
            {
                var genericRepositoryType = typeof(IRepository<>).MakeGenericType(entityType);
                var implType = typeof(EfRepository<,>).MakeGenericType(typeof(DbContext), entityType);
                builder.RegisterType(implType).As(genericRepositoryType);
            }

            builder.RegisterType<CallCurrentUnitOfWorkProvider>().As<ICurrentUnitOfWorkProvider>();
            builder.RegisterType<UnitOfWorkDbContextProvider<DbContext>>().As<IDbContextProvider<DbContext>>();
            builder.RegisterType<EfDbContextProvider<DbContext>>().Keyed<IDbContextProvider<DbContext>>("Default");
            builder.RegisterType<UnitOfWorkManager>().As<IUnitOfWorkManager>();
            builder.RegisterType<EfUnitOfWork>().As<IUnitOfWork>();
        }
开发者ID:cielqian,项目名称:CFramework,代码行数:34,代码来源:DependencyRegistrar.cs


示例9: Create

        /// <inheritdoc />
        public object Create(object target, Type typeOfProxy,
                                                    Type[] additionalInterfacesOfProxy)
        {
            Check.MustNotNull("target", "target");
            Check.MustNotNull("typeToProxy", "typeToProxy");

            var aspects = _aspectsFinder.FindAspects(target.GetType());
            if (!aspects.Any())
            {
                return target;
            }

            var options = new ProxyGenerationOptions
            {
                Selector = new PointcutAspectInterceptorSelector()
            };
            foreach (var instance in this.GetMixinInstances(target.GetType(), aspects))
            {
                options.AddMixinInstance(instance);
            }

            var interceptors = this.GetInterceptors(target.GetType(), aspects);
            if (typeOfProxy.IsInterface)
            {
                return _proxyGenerator.CreateInterfaceProxyWithTarget(typeOfProxy,
                                                       additionalInterfacesOfProxy,
                                                       target, options, interceptors);
            }
            else
            {
                return _proxyGenerator.CreateClassProxyWithTarget(typeOfProxy,
                                                       additionalInterfacesOfProxy,
                                                       target, options, interceptors);
            }
        }
开发者ID:happyframework,项目名称:Happy.Ioc,代码行数:36,代码来源:CastleProxyFactory.cs


示例10: CreateInterfaceProxyTypeWithoutTarget

		public Type CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
		{
			AssertValidType(interfaceToProxy);
			AssertValidTypes(additionalInterfacesToProxy);

			var generator = new InterfaceProxyWithoutTargetGenerator(scope, interfaceToProxy) { Logger = logger };
			return generator.GenerateCode(typeof(object), additionalInterfacesToProxy, options);
		}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:8,代码来源:DefaultProxyBuilder.cs


示例11: GetMethodGenerator

		// 重载 InterfaceProxyWithTargetInterfaceContributor 中的方法,以指定使用扩展的 InvocationType 生成方法执行类
		protected override MethodGenerator GetMethodGenerator(MetaMethod method, ClassEmitter @class, ProxyGenerationOptions options, OverrideMethodDelegate overrideMethod)
		{
			if (!method.Proxyable)
			{
				return new MinimialisticMethodGenerator(method, overrideMethod);
			}
			return new MethodWithInvocationGenerator(method, @class.GetField("__interceptors"), this.GetInvocationType(method, @class, options), this.getTargetExpression, overrideMethod, null);
		}
开发者ID:Kjubo,项目名称:xms.core,代码行数:9,代码来源:WCFInterfaceProxyWithTargetInterfaceTargetContributor.cs


示例12: ReleaseHook

		private void ReleaseHook(ProxyGenerationOptions proxyGenOptions, IKernel kernel)
		{
			if (proxyGenOptions.Hook == null)
			{
				return;
			}
			kernel.ReleaseComponent(proxyGenOptions.Hook);
		}
开发者ID:aledeniz,项目名称:Castle.Windsor,代码行数:8,代码来源:DefaultProxyFactory.cs


示例13: CreateClassProxy

		public virtual Type CreateClassProxy(Type theClass, ProxyGenerationOptions options)
		{
			AssertValidType(theClass);

			ClassProxyGenerator generator = new ClassProxyGenerator(scope, theClass);

			return generator.GenerateCode(null, options);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:8,代码来源:DefaultProxyBuilder.cs


示例14: CreateClassProxyType

		public Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
		{
			AssertValidType(classToProxy);
			AssertValidTypes(additionalInterfacesToProxy);

			var generator = new ClassProxyGenerator(scope, classToProxy) { Logger = logger };
			return generator.GenerateCode(additionalInterfacesToProxy, options);
		}
开发者ID:leloulight,项目名称:Core,代码行数:8,代码来源:DefaultProxyBuilder.cs


示例15: CreateInterfaceProxyTypeWithTargetInterface

		public Type CreateInterfaceProxyTypeWithTargetInterface(Type theInterface, ProxyGenerationOptions options)
		{
			AssertValidType(theInterface);

			InterfaceProxyWithTargetInterfaceGenerator generator =
				new InterfaceProxyWithTargetInterfaceGenerator(scope, theInterface);

			return generator.GenerateCode(theInterface, null, options);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:9,代码来源:DefaultProxyBuilder.cs


示例16: CreateProxyGenerationOptions

		/// <summary>
		/// Creates a context - which is used to guid custom proxy
		/// generation.
		/// </summary>
		/// <param name="mixins">Array of mixins to be registered</param>
		/// <returns>A GeneratorContext instance</returns>
		private static ProxyGenerationOptions CreateProxyGenerationOptions(object[] mixins)
		{
			ProxyGenerationOptions options = new ProxyGenerationOptions();
			foreach (object mixin in mixins)
			{
				options.AddMixinInstance(mixin);
			}
			return options;
		}
开发者ID:atczyc,项目名称:castle,代码行数:15,代码来源:CustomProxyGenerator.cs


示例17: TypedPageActivator

 public TypedPageActivator()
 {
     _generator = new ProxyGenerator();
     _options = new ProxyGenerationOptions(new PageTypePropertiesProxyGenerationHook());
     _interceptors = new IInterceptor[] 
                        {
                            new PageTypePropertyInterceptor()
                        };
 }
开发者ID:eriknordin,项目名称:Page-Type-Builder,代码行数:9,代码来源:TypedPageActivator.cs


示例18: Generate

		public object Generate(IProxyBuilder builder, ProxyGenerationOptions options, IInterceptor[] interceptors, ComponentModel model,
		                       CreationContext context)
		{
			var targetDelegateType = context.RequestedType;
			var type = GetProxyType(builder, targetDelegateType);
			var instance = GetProxyInstance(type, interceptors);
			var method = GetInvokeDelegate(instance, targetDelegateType);
			return method;
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:9,代码来源:DelegateProxyFactory.cs


示例19: Foo1

 public void Foo1()
 {
     ProxyGenerator generator = new ProxyGenerator();
     //Castle.DynamicProxy.IInterceptor[] interceptors = { new MyCastleInterceptor() };
     var options = new ProxyGenerationOptions(new InterceptorFilter()) { Selector = new InterceptorSelector() };
     CastleUserProcessor userProcessor = generator.CreateClassProxy<CastleUserProcessor>(options,new MyCastleInterceptor(), new SimpleLogInterceptor());
     User user = new User() { Name = "lee", PassWord = "123123123123" };
     userProcessor.RegUser(user);
 }
开发者ID:HK-Zhang,项目名称:Grains,代码行数:9,代码来源:CastleInterceptor.cs


示例20: InitElements

        /// <summary>
        /// Initializes the elements in the Page Object.
        /// </summary>
        /// <param name="driver">The driver used to find elements on the page.</param>
        /// <param name="page">The Page Object to be populated with elements.</param>
        public static void InitElements(ISearchContext driver, object page)
        {
            const BindingFlags BindingOptions = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy;
            if (page == null)
            {
                throw new ArgumentNullException("page", "page cannot be null");
            }

            var type = page.GetType();
            var fields = type.GetFields(BindingOptions);
            var properties = type.GetProperties(BindingOptions);
            var members = new List<MemberInfo>(fields);
            members.AddRange(properties);

            foreach (var member in members)
            {
                var attributes = member.GetCustomAttributes(typeof(FindsByAttribute), true);
                foreach (var attribute in attributes)
                {
                    var castedAttribute = (FindsByAttribute)attribute;
                    var generator = new ProxyGenerator();

                    var cacheAttributeType = typeof(CacheLookupAttribute);
                    var cache = member.GetCustomAttributes(cacheAttributeType, true).Length != 0 || member.DeclaringType.GetCustomAttributes(cacheAttributeType, true).Length != 0;

                    var interceptor = new ProxiedWebElementInterceptor(driver, castedAttribute.Bys, cache);

                    var options = new ProxyGenerationOptions
                        {
                            BaseTypeForInterfaceProxy = typeof(WebElementProxyComparer)
                        };

                    var field = member as FieldInfo;
                    var property = member as PropertyInfo;
                    if (field != null)
                    {
                        var proxyElement = generator.CreateInterfaceProxyWithoutTarget(
                            typeof(IWrapsElement),
                            new[] { field.FieldType },
                            options,
                            interceptor);

                        field.SetValue(page, proxyElement);
                    }
                    else if (property != null)
                    {
                        var proxyElement = generator.CreateInterfaceProxyWithoutTarget(
                            typeof(IWrapsElement),
                            new[] { property.PropertyType },
                            options,
                            interceptor);

                        property.SetValue(page, proxyElement, null);
                    }
                }
            }
        }
开发者ID:asynchrony,项目名称:Selenium2,代码行数:62,代码来源:PageFactory.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DynamicProxy.ProxyGenerator类代码示例发布时间:2022-05-24
下一篇:
C# Resource.CustomUri类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap