public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
                                         object value, Type destinationType)
        {
            if ((destinationType == typeof(string)) && (value.GetType() == typeof(AbbreviationMap)))
            {
                AbbreviationMap abbreviations = value as AbbreviationMap;
                string          str           = String.Join(";", Array.ConvertAll(abbreviations.Values.ToArray(), i => i.Key + "," + i.Value));
                return(str);
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Exemple #2
0
        /// <summary>
        /// Handles the editing of the abbreviations when the user presses the browse button.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            if (context == null || provider == null || context.Instance == null)
            {
                return(base.EditValue(provider, value));
            }

            AbbreviationMap           oldAbbreviations = value as AbbreviationMap;
            AbbreviationsEditorDialog dialog           = new AbbreviationsEditorDialog();

            dialog.Abbreviations = oldAbbreviations;

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return(oldAbbreviations);
            }

            return(dialog.Abbreviations);
        }
        public override object ConvertFrom(ITypeDescriptorContext context,
                                           CultureInfo culture, object value)
        {
            if (value != null && value is string)
            {
                AbbreviationMap abbreviations = new AbbreviationMap();
                string          str           = value as string;
                string[]        entries       = str.Split(';');

                foreach (string e in entries)
                {
                    string[] parts = e.Split(',');

                    if (parts.Length == 2)
                    {
                        abbreviations.Add(parts[0], parts[1]);
                    }
                }

                return(abbreviations);
            }

            return(base.ConvertFrom(context, culture, value));
        }