private static object CreateProxyObject(Type memberType, IElementLocator locator, IEnumerable <By> bys, bool cache) { object result = null; if (memberType == typeof(IList <IWebElement>)) { using (List <Type> .Enumerator enumerator = CustomPageObjectMemberDecorator.InterfacesToBeProxied.GetEnumerator()) { while (enumerator.MoveNext()) { Type current = enumerator.Current; Type type = typeof(IList <>).MakeGenericType(new Type[] { current }); if (type.Equals(memberType)) { result = WebElementListProxy.CreateProxy(memberType, locator, bys, cache); break; } } return(result); } } if (!(memberType == typeof(IWebElement))) { throw new ArgumentException("Type of member '" + memberType.Name + "' is not IWebElement or IList<IWebElement>"); } result = WebElementProxy.CreateProxy(CustomPageObjectMemberDecorator.InterfaceProxyType, locator, bys, cache); return(result); }
private static object CreateProxyObject(Type memberType, string name, IElementLocator locator, IEnumerable <By> bys, string containerId, IReporter reporter) { object proxyObject = null; if (memberType == typeof(IWebElement)) { proxyObject = WebElementProxy.CreateProxy(InterfaceProxyType, locator, bys, name, containerId, reporter); } else if (memberType == typeof(IList <IWebElement>)) { proxyObject = WebElementListProxy.CreateProxy(memberType, locator, bys, name, containerId, reporter); } else { throw new ArgumentException("Type of member '" + memberType.Name + "' is not IWebElement or IList<IWebElement>."); } return(proxyObject); }
private static object CreateProxyObject(Type memberType, IElementLocator locator, IEnumerable <By> bys, bool cache) { object proxyObject = null; if (memberType.GetInterfaces().FirstOrDefault(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ICollection <>)) != null && typeof(Element).IsAssignableFrom(memberType.GetGenericArguments()[0])) { ReadOnlyCollection <IWebElement> elements = locator.LocateElements(bys); proxyObject = createListElements(memberType.GetGenericArguments()[0], memberType, elements); } else if (typeof(Element).IsAssignableFrom(memberType)) { IWebElement webElement = (IWebElement)WebElementProxy.CreateProxy(locator, bys, cache); Element element = (Element)memberType.GetConstructor(new[] { typeof(IWebElement) }).Invoke(new object[] { webElement }); PageFactory.InitElements(locator.SearchContext, element, new CustomFieldDecorator()); proxyObject = element; } else { throw new ArgumentException("Type of member '" + memberType.Name + "'Element or IList<Element>"); } return(proxyObject); }