Beispiel #1
0
        private static object?InstantiateMember <T>(FindAttribute findAttribute, IElement container, Type memberType) where T : IElement
        {
            object?element = null;

            if (memberType == typeof(IElement))
            {
                element = WebElement.Create(findAttribute.Nested ? container : default(T),
                                            ElementLocator.Create(findAttribute.SelectorType, findAttribute.SelectorValue));
            }
            else if (memberType == typeof(ISelectElement))
            {
                element = WebElement.CreateSelect(findAttribute.Nested ? container : default(T),
                                                  ElementLocator.Create(findAttribute.SelectorType, findAttribute.SelectorValue));
            }
            else if (typeof(INavigationElement <IPage>).IsAssignableFrom(memberType))
            {
                element = InvokeFactoryMethod("CreateNavigation", memberType.GenericTypeArguments, container, findAttribute);
            }
            else if (typeof(IFrameElement <IPage>).IsAssignableFrom(memberType))
            {
                element = InvokeFactoryMethod("CreateFrame", memberType.GenericTypeArguments, container, findAttribute);
            }
            else if (typeof(IWindowElement <IPage>).IsAssignableFrom(memberType))
            {
                element = InvokeFactoryMethod("CreateWindow", memberType.GenericTypeArguments, container, findAttribute);
            }
            else if (typeof(WebControl).IsAssignableFrom(memberType))
            {
                if (memberType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IListElement <>)))
                {
                    element = InvokeFactoryMethod("CreateList", memberType.GenericTypeArguments, container, findAttribute);
                }
                else
                {
                    element = InvokeFactoryMethod("CreateControl", new Type[] { memberType }, container, findAttribute);
                }
            }

            return(element);
        }
Beispiel #2
0
        private static object InvokeFactoryMethod <T>(string methodName, Type[] genericTypeArguments, T page, FindAttribute findAttribute) where T : IElement
        {
            object     element;
            MethodInfo method  = typeof(WebElement).GetMethod(methodName, BindingFlags.Static | BindingFlags.Public);
            MethodInfo generic = method.MakeGenericMethod(genericTypeArguments);

            element = generic.Invoke(null, new object?[] {
                findAttribute.Nested?page: default,