/// <summary>Converts the given object to the type of this converter, using the specified context and culture information.</summary>
        /// <returns>An <see cref="T:System.Object" /> that represents the converted value.</returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture. </param>
        /// <param name="value">The <see cref="T:System.Object" /> to convert. </param>
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = value as string;

            if (str != null)
            {
                MailAddressCollection collection = new MailAddressCollection();
                collection.Add(str);
                return(collection);
            }

            IEnumerable <string> strs = value as IEnumerable <string>;

            if (strs != null)
            {
                MailAddressCollection collection = new MailAddressCollection();
                foreach (string s in strs)
                {
                    collection.Add(s);
                }

                return(collection);
            }

            IEnumerable <MailAddress> addrs = value as IEnumerable <MailAddress>;

            if (addrs != null)
            {
                MailAddressCollection collection = new MailAddressCollection();
                collection.AddRange(addrs);
                return(collection);
            }

            return(base.ConvertFrom(context, culture, value));
        }
Ejemplo n.º 2
0
 public static void AddRange(this MailAddressCollection collection, string commaSeparatedList)
 {
     if (String.IsNullOrEmpty(commaSeparatedList))
     {
         return;
     }
     collection.AddRange(commaSeparatedList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(a => a.Trim()));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Populates the address list.
 /// </summary>
 /// <param name="addressList">
 /// The address list. 
 /// </param>
 /// <param name="recipients">
 /// The recipients. 
 /// </param>
 public static void PopulateAddressList(string addressList, MailAddressCollection recipients)
 {
     recipients.AddRange(GetMailAddresses(addressList));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Populates the address list.
 /// </summary>
 /// <param name="addressList">
 /// The address list.
 /// </param>
 /// <param name="recipients">
 /// The recipients.
 /// </param>
 public static void PopulateAddressList(string addressList, MailAddressCollection recipients)
 {
     recipients.AddRange(GetMailAddresses(addressList));
 }