MailAddressCollection.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // System.Web.Mail.MailAddressCollection.cs
  3. //
  4. // Author(s):
  5. // Per Arneng <[email protected]>
  6. //
  7. //
  8. using System;
  9. using System.Text;
  10. using System.Collections;
  11. namespace System.Web.Mail {
  12. // represents a collection of MailAddress objects
  13. internal class MailAddressCollection : IEnumerable {
  14. protected ArrayList data = new ArrayList();
  15. public MailAddress this[ int index ] {
  16. get { return this.Get( index ); }
  17. }
  18. public int Count { get { return data.Count; } }
  19. public void Add( MailAddress addr ) { data.Add( addr ); }
  20. public MailAddress Get( int index ) { return (MailAddress)data[ index ]; }
  21. public IEnumerator GetEnumerator() {
  22. return data.GetEnumerator();
  23. }
  24. public override string ToString() {
  25. StringBuilder builder = new StringBuilder();
  26. for( int i = 0; i <data.Count ; i++ ) {
  27. MailAddress addr = this.Get( i );
  28. builder.Append( addr );
  29. if( i != ( data.Count - 1 ) ) builder.Append( ", " );
  30. }
  31. return builder.ToString();
  32. }
  33. public static MailAddressCollection Parse( string str ) {
  34. if( str == null ) throw new ArgumentNullException("Null is not allowed as an address string");
  35. MailAddressCollection list = new MailAddressCollection();
  36. string[] parts = str.Split( new char[] { ',' , ';' } );
  37. foreach( string part in parts ) {
  38. list.Add( MailAddress.Parse( part ) );
  39. }
  40. return list;
  41. }
  42. }
  43. }