Пример #1
0
        /// <summary>
        /// 初始化 <see cref="BindableValue"/> 新实例。
        /// </summary>
        /// <param name="dataSourceType">数据源类型。</param>
        /// <param name="propertyName">属性名称。</param>
        public BindableValue(Type dataSourceType, string propertyName)
        {
            var properties = propertyName.Split('.').ToList();

            if (properties.Count == 1)
            {
                DataSource = null;
                _property  = SourceTypeDescriptor.GetProperty(dataSourceType, properties.Last());
                _property.AddValueChanged(null, OnValueChanged);
            }
            else
            {
                var root = new BindableValue(dataSourceType, properties[0]);
                for (int i = 1; i < properties.Count; i++)
                {
                    var pro = SourceTypeDescriptor.GetProperty(root.Type, properties[i]);
                    if (i == (properties.Count - 1))
                    {
                        DataSource = root.Value;
                        _property  = pro;
                        _property.AddValueChanged(root.Value, OnValueChanged);
                    }
                    else
                    {
                        root.next          = new BindableValue(root.Value, pro);
                        root.next.previous = root;
                        root = root.next;
                    }
                }
            }
        }
Пример #2
0
 private BindableValue(object dataSource, SourcePropertyDescriptor property)
 {
     DataSource = dataSource;
     _property  = property;
     _property.AddValueChanged(dataSource, OnValueChanged);
 }