public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     var service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
     if (service != null && value != null)
     {
         
         // ReSharper disable SuspiciousTypeConversion.Global
         var gridItem = provider as GridItem;
         // ReSharper restore SuspiciousTypeConversion.Global
         var propertyName = value.GetType().Name;
         if (gridItem != null)
         {
             propertyName = gridItem.Label;
         }
         var label = propertyName;
         var oldJson = JsonSerializerHelper.Serialize(value);
         using (var form = new CollectionEditorForm(string.Format("Edit {0}", propertyName), label, value))
         {
             if (service.ShowDialog(form) == DialogResult.OK)
             {
                 if (string.Compare(oldJson,
                                    JsonSerializerHelper.Serialize(value),
                                    StringComparison.InvariantCulture) != 0)
                 {
                     value = GenericCopier<object>.DeepCopy(form.Value);
                 }
             }
         }
     }
     // ReSharper disable AssignNullToNotNullAttribute
     return value;
     // ReSharper restore AssignNullToNotNullAttribute
 } 
Example #2
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (service != null && value != null)
            {
                // ReSharper disable SuspiciousTypeConversion.Global
                var gridItem = provider as GridItem;
                // ReSharper restore SuspiciousTypeConversion.Global
                var propertyName = value.GetType().Name;
                if (gridItem != null)
                {
                    propertyName = gridItem.Label;
                }
                var label   = propertyName;
                var oldJson = JsonSerializerHelper.Serialize(value);
                using (var form = new CollectionEditorForm(string.Format("Edit {0}", propertyName), label, value))
                {
                    if (service.ShowDialog(form) == DialogResult.OK)
                    {
                        if (string.Compare(oldJson,
                                           JsonSerializerHelper.Serialize(value),
                                           StringComparison.InvariantCulture) != 0)
                        {
                            value = GenericCopier <object> .DeepCopy(form.Value);
                        }
                    }
                }
            }
            // ReSharper disable AssignNullToNotNullAttribute
            return(value);
            // ReSharper restore AssignNullToNotNullAttribute
        }