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


C# ProxyGenerator.CreateInterfaceProxyWithoutTarget方法代码示例

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


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

示例1: 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;
            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:v4viveksharma90,项目名称:selenium,代码行数:57,代码来源:PageFactory.cs

示例2: BuildProxy

        public override object BuildProxy(ProxyGenerator generator, Type objType, CommonData data, object baseObj)
        {
            if (!objType.IsInterface)
            {
                throw new Exception("Set can only be created from ISet Interface");
            }

            object proxy;

            if (baseObj == null)
            {
                proxy = generator.CreateInterfaceProxyWithoutTarget(objType,
                    new ProxyGenerationOptions(new GeneralProxyGenerationHook())
                    {
                        Selector = _setSelector
                    },
                    new GeneralGetInterceptor(data), new SetAddInterceptor(data), new SetRemoveInterceptor(data));
            }
            else
            {
                proxy = generator.CreateInterfaceProxyWithTarget(objType, baseObj,
                    new ProxyGenerationOptions(new GeneralProxyGenerationHook())
                    {
                        Selector = _setSelector
                    },
                    new GeneralGetInterceptor(data), new SetAddInterceptor(data), new SetRemoveInterceptor(data));
            }
            return proxy;
        }
开发者ID:DemgelOpenSource,项目名称:DemgelRedis,代码行数:29,代码来源:SetHandler.cs

示例3: InterfaceProxy

        public void InterfaceProxy()
        {
            var generator = new ProxyGenerator();

            var classProxy = generator.CreateInterfaceProxyWithoutTarget<ICollection>();

            var nonProxiedType = ProxyExtracter.GetNonProxiedType(classProxy.GetType());
            Assert.AreEqual(typeof(ICollection),nonProxiedType);
        }
开发者ID:peterjoh,项目名称:NHaml,代码行数:9,代码来源:ProxyExtracterTests.cs

示例4: Create

        public static CommandProxy Create(Type type)
        {
            var generator = new ProxyGenerator();
            var interceptor = new CountingInterceptor();

            var proxy = generator.CreateInterfaceProxyWithoutTarget(type, interceptor);

            return new CommandProxy(interceptor, proxy);
        }
开发者ID:fhtw-swp-tutorium,项目名称:dotNet-swp-test-tool,代码行数:9,代码来源:CommandProxy.cs

示例5: ClassProxyInGenericArgument

        public void ClassProxyInGenericArgument()
        {
            var generator = new ProxyGenerator();

            var classProxy = generator.CreateInterfaceProxyWithoutTarget<ICollection>();

            var genericType = typeof(List<>).MakeGenericType(new[] { classProxy.GetType() });
            var nonProxiedType = ProxyExtracter.GetNonProxiedType(genericType);
            Assert.AreEqual(typeof(List<ICollection>), nonProxiedType);
        }
开发者ID:peterjoh,项目名称:NHaml,代码行数:10,代码来源:ProxyExtracterTests.cs

示例6: Factories_returning_proxies_with_no_target_are_not_supported

		public void Factories_returning_proxies_with_no_target_are_not_supported()
		{
			var generator = new ProxyGenerator();
			Container.Register(Component.For<ICameraService>().UsingFactoryMethod(() => generator.CreateInterfaceProxyWithoutTarget<ICameraService>()));

			var exception = Assert.Throws<NotSupportedException>(() => Container.Resolve<ICameraService>());

			Assert.AreEqual(@"Can not apply commission concerns to component Late bound CastleTests.Components.ICameraService because it appears to be a target-less proxy. Currently those are not supported.",
			                exception.Message);
		}
开发者ID:castleproject,项目名称:Windsor,代码行数:10,代码来源:UsingFactoryMethodTestCase.cs

示例7: Decorate

        public object Decorate(MemberInfo member, IElementLocator locator)
        {
            FieldInfo field = member as FieldInfo;
            PropertyInfo property = member as PropertyInfo;

            Type targetType = null;
            if (field != null)
            {
                targetType = field.FieldType;
            }

            bool hasPropertySet = false;
            if (property != null)
            {
                hasPropertySet = property.CanWrite;
                targetType = property.PropertyType;
            }

            if (field == null & (property == null || !hasPropertySet))
                return null;

            if (field != null && (field.IsStatic || field.IsInitOnly))
                return null;

            Type aSingleElementType = GetTypeOfASingleElement(targetType, member);

            Type aListOfElementsType = null;
            if (GenericsUtility.MatchGenerics(typeof(IList<>), ListOfAvailableElementTypes, targetType))
                aListOfElementsType = targetType;

            if (aSingleElementType == null & aListOfElementsType == null)
                return null;

            ISearchContext context = locator.SearchContext;
            IEnumerable<By> bys = ByFactory.CreateBys(context, member);

            ProxyGenerator generator = new ProxyGenerator();
            TimeOutDuration span = GetTimeWaitingForElements(member);
            bool shouldCache = (Attribute.
                GetCustomAttribute(member, typeof(CacheLookupAttribute), true) != null);

            if (aSingleElementType != null)
                return generator.CreateInterfaceProxyWithoutTarget(aSingleElementType, new Type[] { typeof(IWrapsDriver), typeof(IWrapsElement) },
                    ProxyGenerationOptions.Default, new ElementInterceptor(bys, locator, span, shouldCache));

            return generator.CreateInterfaceProxyWithoutTarget(aListOfElementsType, ProxyGenerationOptions.Default,
                    new ElementListInterceptor(bys, locator, span, shouldCache));
        }
开发者ID:trbnb,项目名称:appium-dotnet-driver,代码行数:48,代码来源:AppiumPageObjectMemberDecorator.cs

示例8: CreateForNoImplementation

 private ITestInterfaceWithoutImplementation CreateForNoImplementation()
 {
     var generator = new ProxyGenerator();
     return (ITestInterfaceWithoutImplementation) generator.CreateInterfaceProxyWithoutTarget(typeof(ITestInterfaceWithoutImplementation), new CommandInterceptor());
 }
开发者ID:hudl,项目名称:Mjolnir,代码行数:5,代码来源:CommandAttributeAndProxyTests.cs

示例9: ProxyMe

 public IComparable ProxyMe(ProxyGenerator generator, IInterceptor interceptor)
 {
     return generator.CreateInterfaceProxyWithoutTarget<IComparable>(interceptor);
 }
开发者ID:spraints,项目名称:nupack-restore-package,代码行数:4,代码来源:Form1.cs

示例10: Create

 public object Create(PropertyInfo propertyInfo)
 {
     var generator = new ProxyGenerator();
     var proxy = generator.CreateInterfaceProxyWithoutTarget(propertyInfo.PropertyType, _interceptors);
     return proxy;
 }
开发者ID:kevholditch,项目名称:StronglyTypedContext,代码行数:6,代码来源:ProxyFactory.cs

示例11: CreateFactory

        public Func<INode, object> CreateFactory()
        {
            //if local point to data, then local retrieves the underlying template node
            //standard local behavior instantiates the object as a singleton from the template
            //If data pass the actual data, if virtualizable, wrap it (there might a flag to have it only wrap if it needs to)

            var get = _attribute.Get<IAccessor<string>>();
            var path = Decoder.FromPath(get.Value);
            return dataNode =>
                       {
                           if (get.Value == "[@rows][1]")
                           {
                               var firstExpr = path.Expressions.First();
                               var firstResult = firstExpr.Invoke(_attribute.Parent);
                               var objResult = _fnNodeBuilder((INode)firstResult, dataNode, typeof(object));
            //                               throw new Exception("Debug from here.  For some reason what it's doing here is causing infinite recursion.");
                               return null;
                           }
                           //TODO: I think this will be needed to support certain orderings of properties
            /*                            var existingObject = _attribute
                                .GetType()
                                .GetMethod("Get")
                                .MakeGenericMethod(_propertyType)
                                .Invoke(_attribute, new object[] {});*/

                           if (path.Data != null)
                           {
                               var fnData = path.Data.Compile();
                               var dataResult = fnData.DynamicInvoke(dataNode);
                               if (dataResult is IEndNode)
                               {
                                   var endNode = (IEndNode) dataResult;
                                   var accessor = endNode.Get<IAccessor<string>>();
                                   if (path.Data.ToString() == "a => a.Attribute(\"desc\")")
                                   {
                                       return accessor.Value;
                                   }
                               }
                           }
                           if (path.Local == null) return null;

                           var fnLocal = path.Local.Compile();
                           var di = fnLocal.DynamicInvoke(_attribute.Parent);
                           if (!typeof(IEnumerable<IParentNode>).IsAssignableFrom(di.GetType()))
                           {
                               if (typeof(INode).IsAssignableFrom(di.GetType()))
                               {
                                   //take di, and call _fnNodeBuilder
                                   if (path.Data == null)
                                   {
                                       if (typeof(IEndNode).IsAssignableFrom(di.GetType()))
                                       {
                                           return _fnNodeBuilder((INode)di, dataNode, _propertyType);
                                       }
                                       var newObj = _fnNodeBuilder((IParentNode)di, dataNode, typeof(object));
                                       if (!_propertyType.IsAssignableFrom(newObj.GetType()))
                                       {
                                           var proxy = new ProxyGenerator();
                                           return proxy.CreateInterfaceProxyWithoutTarget(_propertyType, new SuperCast(newObj));
                                       }
                                       return newObj;
                                   }
                               }
                               //TODO: Implement this.  This is [:selector/@rowSelector]{@body}
                               return null;
                           }
                           var result = (IEnumerable<IParentNode>)fnLocal.DynamicInvoke(_attribute.Parent);
                           //TODO: instead of this it should actually be for each dataNode as well

                           IEnumerable<object> finalResult;
                           if (path.Data == null)
                               finalResult = result.Select(templateNode => _fnNodeBuilder(templateNode, dataNode, typeof(object)));
                           else
                           {
                               //TODO: if _propertyType does not have a nested IEnumerable and result.Count() > 1, Fail!

                               var fnData = path.Data.Compile();
                               var dataResult = fnData.DynamicInvoke(dataNode);
                               var eResult = ((IEnumerable) dataResult).Cast<IParentNode>();
                               finalResult = eResult.Select(e => _fnNodeBuilder(result.First(), e, typeof(object)));
            //                               finalResult = result.Select(templateNode => _fnNodeBuilder(templateNode, dataNode));
                           }
                           finalResult = finalResult.ToList();

                           if (!_propertyType.IsAssignableFrom(finalResult.GetType()))
                           {
                               if (typeof(IEnumerable).IsAssignableFrom(_propertyType))
                               {
                                   //I can use supercast
                                   var enumCastType = _propertyType.GetGenericArguments().First();
                                   var castMethod = typeof(Enumerable).GetMethod("Cast");
                                   castMethod = castMethod.MakeGenericMethod(enumCastType);
                                   var newFinalResult = castMethod.Invoke(null, new[] { finalResult });
                                   return newFinalResult;
                               }
                               var fields = finalResult.Cast<UITemplateViewer.WPF.IField>();
                           }
            //                           fnNodeBuilder((IParentNode)result, dataNode);

                           //now create a new object
//.........这里部分代码省略.........
开发者ID:mcwatt77,项目名称:vimcontrols,代码行数:101,代码来源:PathObjectFactory.cs

示例12: CreateServiceInterceptor

 public IService CreateServiceInterceptor(IComponentContext componentContext)
 {
     var generator = new ProxyGenerator();
     return generator.CreateInterfaceProxyWithoutTarget<IService>(componentContext.Resolve<ServiceInterceptor>());
 }
开发者ID:adbrowne,项目名称:Samples,代码行数:5,代码来源:Class1.cs


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