/// <summary>
        /// A <see cref="System.ComponentModel.PropertyDescriptor" /> for nested
        /// properties. That is for properties of properties.
        /// </summary>
        /// <param name="type">The component type for which the nested property belongs.</param>
        /// <param name="propertyName">
        /// The nested property name specified using dot notation. This should not contain
        /// the name of component itself.
        /// </param>
        public NestedPropertyDescriptor(Type type, string propertyName)
            : base(Check.NotEmpty(propertyName, "propertyName"), null)
        {
            Check.NotNull(type, "type");

            var propMap = propertyName.Split('.');

            Type currtype = type;

            _parentPD = null;

            int i = 0;

            do
            {
                _currentPD = TypeDescriptor.GetProperties(currtype).Find(propMap[i], false);
                if (_currentPD == null)
                {
                    throw new ArgumentException("The specified nested property does not exist.", "propertyName");
                }

                i++;
                if (i == propMap.Length)
                {
                    break;
                }

                _parentPD = new NestedPropertyDescriptor(_currentPD, _parentPD);

                currtype = _currentPD.PropertyType;
            }while (true);
        }
        /// <summary>
        /// A <see cref="System.ComponentModel.PropertyDescriptor" /> for nested
        /// properties. That is for properties of properties.
        /// </summary>
        /// <param name="type">The component type for which the nested property belongs.</param>
        /// <param name="propertyName">
        /// The nested property name specified using dot notation. This should not contain
        /// the name of component itself.
        /// </param>
        public NestedPropertyDescriptor(Type type, string propertyName)
            : base(Check.NotEmpty(propertyName, "propertyName"), null)
        {
            Check.NotNull(type, "type");

            var propMap = propertyName.Split('.');

            Type currtype = type;
            _parentPD = null;

            int i = 0;
            do
            {
                _currentPD = TypeDescriptor.GetProperties(currtype).Find(propMap[i], false);
                if (_currentPD == null)
                    throw new ArgumentException("The specified nested property does not exist.", "propertyName");

                i++;
                if (i == propMap.Length)
                    break;

                _parentPD = new NestedPropertyDescriptor(_currentPD, _parentPD);

                currtype = _currentPD.PropertyType;
            }
            while (true);
        }
 private NestedPropertyDescriptor(PropertyDescriptor pd, NestedPropertyDescriptor parent = null)
     : base(parent == null
             ? DebugCheck.NotNull(pd, "pd").Name
             : string.Format("{0}.{1}", parent.Name, DebugCheck.NotNull(pd, "pd").Name),
            null)
 {
     _currentPD = pd;
     _parentPD  = parent;
 }
 private NestedPropertyDescriptor(PropertyDescriptor pd, NestedPropertyDescriptor parent = null)
     : base(parent == null
             ? DebugCheck.NotNull(pd, "pd").Name
             : string.Format("{0}.{1}", parent.Name, DebugCheck.NotNull(pd, "pd").Name),
             null)
 {
     _currentPD = pd;
     _parentPD = parent;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Create a new <see cref="NestedPropertyChangeNotifier{T}" /> for type T and the
        /// given depth of nested properties.
        /// </summary>
        public NestedPropertyChangedNotifier(int depth = 1)
        {
            CascadeNotifications = true;

            this.depth = depth;
            var pds = NestedPropertyDescriptor.GetNestedProperties(typeof(T), depth);

            properties = pds.ToDictionary(pd => pd.Name);
            var npcPds = pds.Where(npd =>
                                   typeof(INotifyPropertyChanged).IsAssignableFrom(npd.PropertyType) &&
                                   npd.PropertyDepth != depth);

            notifiers = new Dictionary <string, InnerNotifier>();

            foreach (var npd in npcPds)
            {
                var notifier = new InnerNotifier(npd);
                notifiers[npd.Name] = notifier;

                notifier.PropertyChanged += NestedPropertyChanged;
            }
        }
        private static IEnumerable <NestedPropertyDescriptor> GetNestedProperties(
            Type type, int depth = 1, bool includeValueTypes = false, NestedPropertyDescriptor parent = null)
        {
            Debug.Assert(depth >= 0);

            if (!includeValueTypes && (type.IsValueType || type == typeof(string)))
            {
                yield break;
            }

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(type))
            {
                var npd = new NestedPropertyDescriptor(pd, parent);
                yield return(npd);

                if (depth > 0)
                {
                    foreach (var childpd in GetNestedProperties(npd.PropertyType, depth - 1, includeValueTypes, npd))
                    {
                        yield return(childpd);
                    }
                }
            }
        }
        private static IEnumerable<NestedPropertyDescriptor> GetNestedProperties(
            Type type, int depth = 1, bool includeValueTypes = false, NestedPropertyDescriptor parent = null)
        {
            Debug.Assert(depth >= 0);

            if (!includeValueTypes && (type.IsValueType || type == typeof(string)))
                yield break;

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(type))
            {
                var npd = new NestedPropertyDescriptor(pd, parent);
                yield return npd;

                if (depth > 0)
                {
                    foreach (var childpd in GetNestedProperties(npd.PropertyType, depth - 1, includeValueTypes, npd))
                        yield return childpd;
                }
            }
        }