예제 #1
0
        /// <summary>
        /// Edits the value of the specified object using the specified service provider and context.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that can be used to gain additional context information. </param>
        /// <param name="provider">A service provider object through which editing services can be obtained.</param>
        /// <param name="value">The object to edit the value of.</param>
        /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.PropertyDescriptor != null && context.PropertyDescriptor.Attributes[typeof(GenericDictionaryEditorAttribute)] is GenericDictionaryEditorAttribute attribute)
            {
                _mEditorAttribute = attribute;

                if (_mEditorAttribute.KeyDefaultProviderType == null)
                {
                    _mEditorAttribute.KeyDefaultProviderType = typeof(DefaultProvider <TKey>);
                }

                if (_mEditorAttribute.ValueDefaultProviderType == null)
                {
                    _mEditorAttribute.ValueDefaultProviderType = typeof(DefaultProvider <TValue>);
                }
            }
            else
            {
                _mEditorAttribute = new GenericDictionaryEditorAttribute
                {
                    KeyDefaultProviderType   = typeof(DefaultProvider <TKey>),
                    ValueDefaultProviderType = typeof(DefaultProvider <TValue>)
                };
            }

            return(base.EditValue(context, provider, value));
        }
        public EditableKeyValuePair(TKey key, TValue value, GenericDictionaryEditorAttribute editorAttribute)
        {
            Key   = key;
            Value = value;

            EditorAttribute = editorAttribute ?? throw new ArgumentNullException(nameof(editorAttribute));
        }