public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                IWindowsFormsEditorService        edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                ICollectionAApiVersionedFieldsCTD field = (ICollectionAApiVersionedFieldsCTD)value;
                NewGridForm ui = new NewGridForm((IGenericAdd)field.owner[field.field].Value);

                edSvc.ShowDialog(ui);

                return(field.owner[field.field].Value);
            }
Esempio n. 2
0
            public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                IDictionaryCTD field = (IDictionaryCTD)value;

                if (field.Value == null)
                {
                    return(value);
                }

                int count = 0;

                Type[] interfaces = field.Value.GetType().GetInterfaces();
                for (int i = 0; i < interfaces.Length; i++)
                {
                    if (interfaces[i].Name == "IDictionary`2")
                    {
                        count++;
                    }
                }
                if (count != 1)
                {
                    return(value);
                }
                DictionaryEntry entry = getDefault(field.Value.GetType());

                List <object> oldKeys = new List <object>();
                AsKVPList     list    = new AsKVPList(entry);

                foreach (var k in field.Value.Keys)
                {
                    list.Add(new AsKVP(0, null, k, field.Value[k])); oldKeys.Add(k);
                }

                NewGridForm ui = new NewGridForm(list);

                edSvc.ShowDialog(ui);

                List <object> newKeys = new List <object>();

                foreach (AsKVP kvp in list)
                {
                    newKeys.Add(kvp["Key"].Value);
                }

                List <object> delete = new List <object>();

                foreach (var k in field.Value.Keys)
                {
                    if (!newKeys.Contains(k))
                    {
                        delete.Add(k);
                    }
                }
                foreach (object k in delete)
                {
                    field.Value.Remove(k);
                }

                bool dups = false;

                foreach (AsKVP kvp in list)
                {
                    if (oldKeys.Contains(kvp["Key"].Value))
                    {
                        field.Value[kvp["Key"].Value] = kvp["Val"].Value;
                    }
                    else if (!field.Value.Contains(kvp["Key"].Value))
                    {
                        field.Value.Add(kvp["Key"].Value, kvp["Val"].Value);
                    }
                    else
                    {
                        dups = true;
                    }
                }
                if (dups)
                {
                    CopyableMessageBox.Show("Duplicate keyed entries were dropped.", "s3pe", CopyableMessageBoxButtons.OK, CopyableMessageBoxIcon.Warning);
                }

                return(value);
            }