示例#1
0
        private object GetValue(object o)
        {
            var    source = FindSource(o);
            object value  = null;

            if (string.IsNullOrEmpty(this.Path))
            {
                //当没有指定path时,以源作为value
                value = source;
            }
            else
            {
                var dtoSource = source as DTObject;
                if (dtoSource != null)
                {
                    value = dtoSource.GetValue(this.Path);
                }
                else
                {
                    value = RuntimeUtil.GetPropertyValue(source, this.Path);
                }
            }

            if (this.Converter != null)
            {
                value = this.Converter.Convert(value, this.Parameter);
            }
            return(value);
        }
        private object GetValueFromSource(object target)
        {
            if (_source == null)
            {
                return(null);
            }

            object value = null;
            var    ui    = _source as UIElement;

            if (ui != null)
            {
                value = ui.GetValue(_sourceProperty);
            }
            else
            {
                value = RuntimeUtil.GetPropertyValue(_source, this.PropertyName);
            }

            if (this.Converter != null)
            {
                value = this.Converter.Convert(value, this.Parameter);
            }
            return(value);
        }
示例#3
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;
                }
            }
        }
        private object GetValue(object d)
        {
            var    source    = this.SourceFinder.Find(d);
            object value     = null;
            var    dtoSource = source as DTObject;

            if (dtoSource != null)
            {
                value = dtoSource.GetValue(this.Path);
            }
            else
            {
                value = RuntimeUtil.GetPropertyValue(source, this.Path);
            }

            if (this.Converter != null)
            {
                value = this.Converter.Convert(value, this.Parameter);
            }
            return(value);
        }
        /// <summary>
        /// 根据路径定位source,并返回绑定的属性名称
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private object LocateSource(object source)
        {
            var path = this.Path;

            if (path.IndexOf(".") == -1)
            {
                return(source);
            }

            var propertyNames = path.Split('.');
            var value         = source;
            var lastIndex     = propertyNames.Length - 1;

            for (var i = 0; i < lastIndex; i++)
            {
                var propertyName = propertyNames[i];
                value = RuntimeUtil.GetPropertyValue(value, propertyName);
                if (value == null)
                {
                    break;
                }
            }
            return(value);
        }