예제 #1
0
            public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
            {
                IDictionaryCTD ctd = value as IDictionaryCTD;
                IDictionary    id  = (IDictionary)ctd.Value;

                if (typeof(string).Equals(destinationType))
                {
                    return(id == null ? "(null)" : "(Dictionary: 0x" + id.Count.ToString("X") + ")");
                }
                return(base.ConvertTo(context, culture, value, destinationType));
            }
예제 #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);
            }