Ejemplo n.º 1
0
        /// <summary>
        ///     Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">A System.ComponentModel.ITypeDescriptorContext that provides a format context.</param>
        /// <param name="culture">The System.Globalization.CultureInfo to use as the current culture.</param>
        /// <param name="value">The System.Object to convert.</param>
        /// <returns>
        ///     An <see cref="ActiveCommand"/> that represents the converted value.
        /// </returns>
        /// <remarks>
        ///     Compare a name with known command names and return the courresponding <see cref="ActiveCommand"/>.
        /// </remarks>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string AsString;

            if ((AsString = value as string) != null)
            {
                ActiveCommand Result;
                if (ActiveCommandTypeConverter.TryParseName(AsString, out Result))
                {
                    return(Result);
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">A System.ComponentModel.ITypeDescriptorContext that provides a format context.</param>
        /// <param name="culture">The System.Globalization.CultureInfo to use as the current culture.</param>
        /// <param name="value">The System.Object to convert.</param>
        /// <returns>
        /// An <see cref="ActiveCommandCollection"/> that represents the converted value.
        /// </returns>
        /// <remarks>
        /// <para>This method will convert a string with format "&lt;commandname&gt;, ..." where &lt;commandname&gt; is the name of one of the supported commands.</para>
        /// </remarks>
        /// <example>
        /// <code>
        /// "OK, Cancel, Yes, No"
        /// </code>
        /// </example>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string AsString)
            {
                string[] StringList = AsString.Split(',');

                ActiveCommandCollection Result = new ActiveCommandCollection();
                foreach (string Name in StringList)
                {
                    ActiveCommandTypeConverter.TryParseName(Name.Trim(), (ActiveCommand command) => Result.Add(command));
                }

                return(Result);
            }

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