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


C# ProxyGenerator.CreateClassProxy方法代码示例

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


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

示例1: DynamicProxyHelper

        public DynamicProxyHelper(SerializationInfo info, StreamingContext context)
        {
            _info = info;
            _context = context;

            _argumentsForConstructor = (Type[])info.GetValue(DynamicPropertyChangedProxy.ARGUMENTS_TYPES4CONSTRUCTOR, typeof(Type[]));
            _valuesForConstructor = (object[])info.GetValue(DynamicPropertyChangedProxy.VALUES4CONSTRUCTOR, typeof(object[]));
            _baseTypeName = (string)info.GetValue(DynamicPropertyChangedProxy.OBJECT_BASE_TYPE, typeof(string));
            bool isBusinessObj = (bool)info.GetValue(DynamicPropertyChangedProxy.IS_BUSINESS_OBJECT, typeof(bool));
            _baseT = Type.GetType(_baseTypeName, true, false);
            Type firstProxyType;
            object[] baseMemberData = (object[])_info.GetValue(DynamicPropertyChangedProxy.SERIALIZED_DATA, typeof(object[]));
            ProxyGenerator generator = new ProxyGenerator();

            if (isBusinessObj)
            {
                // the business objects have to have a default constructor
                firstProxyType = DynamicPropertyChangedProxy.CreateBusinessObjectProxy(_baseT, _argumentsForConstructor);
                _proxy = generator.CreateClassProxy(firstProxyType, (IInterceptor[])baseMemberData[0]);
            }
            else
            {
                // if it is not a business object then it has to be a BindableFields class which constructor has always an interceptor
                firstProxyType = DynamicPropertyChangedProxy.CreateBindableWrapperProxy(_baseT, _argumentsForConstructor, _valuesForConstructor);
                _proxy = generator.CreateClassProxy(firstProxyType, (IInterceptor[])baseMemberData[0], _valuesForConstructor);
            }
        }
开发者ID:BackupTheBerlios,项目名称:boxerp-svn,代码行数:27,代码来源:DynamicProxyHelper.cs

示例2: DynamicProxy

 public void DynamicProxy()
 {
     var g = new ProxyGenerator();
     //g.CreateInterfaceProxyWithTarget()
     var cs = g.CreateClassProxy<ComparerCS>(new TestInterceptor()) as IComparer;
     var cs2 = g.CreateClassProxy(typeof (ComparerCS), new[] {typeof (IComparer)}, new TestInterceptor()) as IComparer;
     var vb = g.CreateClassProxy<ComparerVB>(new TestInterceptor()) as IComparer;
     var fs = g.CreateClassProxy<ComparerFS>(new TestInterceptor()) as IComparer;
     cs.Compare(0, 0);
     cs2.Compare(0, 0);
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:11,代码来源:ProxyTests.cs

示例3: InitializeProxy

 public void InitializeProxy()
 {
     IBar bar = new Bar();
     var pg = new ProxyGenerator();
     this.BarInterfaceProxy = pg.CreateInterfaceProxyWithTarget(bar, new CacheInterceptor());
     this.FooBarProxy = pg.CreateClassProxy<FooBar>(new CacheInterceptor());
 }
开发者ID:Krishna-Desiraju,项目名称:CacheInterceptor,代码行数:7,代码来源:CacheAttributeTests.cs

示例4: Parallel

 public void Parallel()
 {
     var generator = new ProxyGenerator();
     var t = generator.CreateClassProxy<SomethingToIntercept>(new ProcessInterceptor());
     var r = Enumerable.Range(0, 100).AsParallel().Sum(i => t.Add(i, i));
     Assert.AreEqual(9900, r);
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:7,代码来源:Tests.cs

示例5: NullReturn

 public void NullReturn()
 {
     var generator = new ProxyGenerator();
     var t = generator.CreateClassProxy<SomethingToIntercept>(new ProcessInterceptor());
     var r = t.NullReturn();
     Assert.IsNull(r);
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:7,代码来源:Tests.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: Call

 public void Call()
 {
     var generator = new ProxyGenerator();
     var t = generator.CreateClassProxy<SomethingToIntercept>(new ProcessInterceptor());
     var r = t.DoSomething("a", "b");
     Assert.AreEqual("ab", r);
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:7,代码来源:Tests.cs

示例8: 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

示例9: CreateProxy

 private object CreateProxy(Type type, object settings)
 {
     var proxyGenerator = new ProxyGenerator();
     var settingsInterceptor = SetInterceptor(type, settings);
     var proxy = proxyGenerator.CreateClassProxy(type, settingsInterceptor);
     return proxy;
 }
开发者ID:mamluka,项目名称:SpeedyMailer,代码行数:7,代码来源:DocumentStoreSettingBinder.cs

示例10: WrapInterface

 /// <summary>
 /// �����ʽʵ��������
 /// </summary>
 /// <param name="engine"></param>
 /// <returns></returns>
 public static object WrapInterface(Type engine)
 {
     ProxyInterceptor proxyInterceptor = new ProxyInterceptor();
     ProxyGenerator generator = new ProxyGenerator();
     object proxy = generator.CreateClassProxy(engine, proxyInterceptor);
     return proxy;
 }
开发者ID:BGCX261,项目名称:zhuji-cms-svn-to-git,代码行数:12,代码来源:Operator.cs

示例11: Main

 static void Main(string[] args)
 {
     System.Console.WriteLine("现在是Castle的代理在运行");
     ProxyGenerator generator = new ProxyGenerator();
     object proxy = generator.CreateClassProxy(typeof(RealA), new ProxyInterceptor());
     (proxy as RealA).DoSomething();
     System.Console.ReadLine();
 }
开发者ID:rogerxing90,项目名称:CastleDemo,代码行数:8,代码来源:Program.cs

示例12: Main

 static void Main(string[] args)
 {
     var proxyGenerator = new ProxyGenerator();
     var svc = proxyGenerator
         .CreateClassProxy<TwitterClient>(
             new MyInterceptorAspect());
     svc.Send("hi");
 }
开发者ID:hurricanepkt,项目名称:AOPinNET,代码行数:8,代码来源:Program.cs

示例13: Foo1

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

示例14: LoadObjectDefinitions

 protected override void LoadObjectDefinitions(DefaultListableObjectFactory objectFactory)
 {
     //wrap the objectFactory with our own proxy so that we keep track of the objects ids defined in the Spring.NET context
     callbacks.Add(new BeanohObjectFactoryMethodInterceptor(objectFactory));
     ProxyGenerator generator = new ProxyGenerator();
     DefaultListableObjectFactory wrapper = (DefaultListableObjectFactory)generator.CreateClassProxy(objectFactory.GetType(), callbacks.ToArray());
     //delegate to our proxy
     base.LoadObjectDefinitions(wrapper);
 }
开发者ID:mattcvincent,项目名称:beanoh.NET,代码行数:9,代码来源:BeanohApplicationContext.cs

示例15: 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


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