コード例 #1
0
        private void Load(object obj, HtmlNode objNode)
        {
            //设置加载上下文
            var connector = obj as IComponentConnector;
            var ctx       = new LoadContext(connector);

            LoadContext.Push(ctx);

            try
            {
                //加载元素信息
                var loader = ComponentLoaderFactory.Create(obj, objNode);
                loader.LoadComponent(obj, objNode);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                LoadContext.Pop();
            }
        }
コード例 #2
0
        /// <summary>
        /// 根据节点创建组件,该方法内部使用,不会新建加载上下文
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        internal static object CreateComponent(HtmlNode node, object parent)
        {
            var obj  = ComponentFactory.Create(node.OriginalName);
            var type = obj as Type;

            if (type != null)
            {
                //是基础类型
                return(DataUtil.ToValue(node.InnerHtml, type));
            }
            else
            {
                var e = obj as UIElement;
                if (e != null)
                {
                    e.SetValue(UIElement.ParentProperty, parent);
                }

                //加载元素信息
                var loader = ComponentLoaderFactory.Create(obj, node);
                loader.LoadComponent(obj, node);
                return(obj);
            }
        }