Beispiel #1
0
        private void LoadInnerProperty(LoadContext ctx, object obj, string innerName, string attrValue)
        {
            var current       = obj;
            var propertyNames = innerName.Split('.');
            var lastIndex     = propertyNames.Length - 1;

            for (var i = 0; i < propertyNames.Length; i++)
            {
                var propertyName = propertyNames[i];
                if (i == lastIndex)
                {
                    ctx.PushObject(current);
                    ctx.PushProperty(propertyName);
                    LoadSingleSimple(current.GetType(), current, propertyName, attrValue);
                    ctx.PushProperty(propertyName);
                    ctx.PopObject();
                }
                else
                {
                    var target = RuntimeUtil.GetPropertyValue(current, propertyName);
                    if (target == null)
                    {
                        throw new XamlException("类型" + current.GetType().FullName + "的属性" + propertyName + "值为null,无法赋值");
                    }
                    current = target;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 这是一个重构方法,内部使用
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="objType"></param>
        /// <param name="obj"></param>
        /// <param name="attr"></param>
        private void LoadSimple(LoadContext ctx, Type objType, object obj, HtmlAttribute attr)
        {
            if (IsSimpleProperty(attr))
            {
                var propertyName = attr.OriginalName;

                ctx.PushProperty(propertyName);
                LoadSingleSimple(objType, obj, propertyName, attr.Value);
                ctx.PopProperty();
            }
            else if (IsInnerProperty(attr))
            {
                var innerName = attr.OriginalName;
                ctx.PushProperty(innerName);
                LoadInnerProperty(ctx, obj, innerName, attr.Value);
                ctx.PopProperty();
            }
        }
        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();
            }
        }
 public static void Push(LoadContext ctx)
 {
     Contexts.Push(ctx);
 }