예제 #1
0
        /// <summary>
        /// Build the page
        /// </summary>
        /// <param name="pageInstance"></param>
        public void Build(object pageInstance)
        {
            MemberInfo[] membersToBuild = GetElementsMemberInfo(pageInstance.GetType());

            foreach (MemberInfo memberInfo in membersToBuild)
            {
                SearchConfiguratiuon searchConfiguratiuon = BuildSearchConfig(memberInfo);
                Type type = GetMemberType(memberInfo);

                if (type.IsSubclassOf(typeof(Container)))
                {
                    object instance = new ContainerBuilder().Build(memberInfo, searchConfiguratiuon);
                    SetMemberValue(memberInfo, pageInstance, instance);
                    continue;
                }
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(HtmlElementsCollection <>))
                {
                    object instance = new HtmlElementsCollectionBuilder().Build(memberInfo, searchConfiguratiuon);
                    SetMemberValue(memberInfo, pageInstance, instance);
                    continue;
                }
                if (type.IsSubclassOf(typeof(HtmlElement)) || type == typeof(HtmlElement))
                {
                    object instance = Initialize(type, searchConfiguratiuon);
                    SetMemberValue(memberInfo, pageInstance, instance);
                }
            }
        }
        /// <summary>
        /// Return the webElement container instance
        /// </summary>
        public object Build(MemberInfo containerMemberInfo, SearchConfiguration configuration)
        {
            Type containerType     = GetMemberType(containerMemberInfo);
            var  containerInstance = Initialize(containerType, configuration);

            _currentContainer = (HtmlElement)containerInstance;
            MemberInfo[] membersToBuild = GetElementsMemberInfo(containerType);

            foreach (MemberInfo memberInfo in membersToBuild)
            {
                SearchConfiguration searchConfiguration = BuildSearchConfig(memberInfo, _currentContainer);
                Type memberType = GetMemberType(memberInfo);

                if (memberType.IsGenericType &&
                    memberType.GetGenericTypeDefinition() == typeof(HtmlElementsCollection <>))
                {
                    object instance = new HtmlElementsCollectionBuilder().Build(memberInfo, searchConfiguration);
                    SetMemberValue(memberInfo, containerInstance, instance);
                    continue;
                }
                if (memberType.IsSubclassOf(typeof(Container)))
                {
                    object instance = new ContainerBuilder().Build(memberInfo, searchConfiguration);
                    SetMemberValue(memberInfo, containerInstance, instance);
                    continue;
                }
                if (memberType.IsSubclassOf(typeof(HtmlElement)) || memberType == typeof(HtmlElement))
                {
                    object instance = base.Initialize(memberType, searchConfiguration);
                    SetMemberValue(memberInfo, containerInstance, instance);
                }
            }
            return(containerInstance);
        }