Exemplo n.º 1
0
        /// <summary>
        /// Sets the properties from descriptor.
        /// </summary>
        /// <param name="pd">The property definition.</param>
        /// <param name="descriptor">The descriptor.</param>
        /// <exception cref="System.ArgumentException"></exception>
        protected virtual void SetPropertiesFromDescriptor(PropertyDefinition pd, PropertyDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentException(nameof(descriptor));
            }

            if (descriptor.GetAttributeValue <System.ComponentModel.ReadOnlyAttribute, bool>(a => a.IsReadOnly) ||
                descriptor.GetAttributeValue <DataAnnotations.ReadOnlyAttribute, bool>(a => a.IsReadOnly) ||
                descriptor.IsReadOnly)
            {
                pd.IsReadOnly = true;
            }

            var ispa = descriptor.GetFirstAttributeOrDefault <ItemsSourcePropertyAttribute>();

            if (ispa != null)
            {
                pd.ItemsSourceProperty = ispa.PropertyName;
            }

            var eba = descriptor.GetFirstAttributeOrDefault <EnableByAttribute>();

            if (eba != null)
            {
                pd.IsEnabledByProperty = eba.PropertyName;
                pd.IsEnabledByValue    = eba.PropertyValue;
            }
        }
        /// <summary>
        /// Sets the properties from descriptor.
        /// </summary>
        /// <param name="pd">The property definition.</param>
        /// <param name="descriptor">The descriptor.</param>
        protected virtual void SetPropertiesFromDescriptor(PropertyDefinition pd, PropertyDescriptor descriptor)
        {
            if (descriptor == null)
            {
                return;
            }

            if (descriptor.GetAttributeValue <System.ComponentModel.ReadOnlyAttribute, bool>(a => a.IsReadOnly) ||
                descriptor.GetAttributeValue <DataAnnotations.ReadOnlyAttribute, bool>(a => a.IsReadOnly) ||
                descriptor.IsReadOnly)
            {
                pd.IsReadOnly = true;
            }

            if (descriptor.GetAttributeValue <System.ComponentModel.DataAnnotations.EditableAttribute, bool>(a => a.AllowEdit) ||
                descriptor.GetAttributeValue <EditableAttribute, bool>(a => a.AllowEdit))
            {
                pd.IsEditable = true;
            }

            var ispa = descriptor.GetFirstAttributeOrDefault <ItemsSourcePropertyAttribute>();

            if (ispa != null)
            {
                pd.ItemsSourceProperty = ispa.PropertyName;
            }

            var svpa = descriptor.GetFirstAttributeOrDefault <SelectedValuePathAttribute>();

            if (svpa != null)
            {
                pd.SelectedValuePath = svpa.Path;
            }

            var dmpa = descriptor.GetFirstAttributeOrDefault <DisplayMemberPathAttribute>();

            if (dmpa != null)
            {
                pd.DisplayMemberPath = dmpa.Path;
            }

            var eba = descriptor.GetFirstAttributeOrDefault <EnableByAttribute>();

            if (eba != null)
            {
                pd.IsEnabledByProperty = eba.PropertyName;
                pd.IsEnabledByValue    = eba.PropertyValue;
            }
        }