/// <summary> /// Creates a new <see cref="EmailAddress"/> using the specified email address parts. /// </summary> /// <param name="accountPart">The account part (required).</param> /// <param name="tagPart">The tag part.</param> /// <param name="domainPart">The domain part (required).</param> /// <exception cref="System.ArgumentException"> /// The value cannot be empty;localPart /// or /// The value cannot be empty;domainPart /// or /// Invalid email address;address /// </exception> public EmailAddress(string accountPart, string tagPart, string domainPart) { if (string.IsNullOrEmpty(accountPart)) { throw new ArgumentException("The value cannot be empty", "localPart"); } if (string.IsNullOrEmpty(domainPart)) { throw new ArgumentException("The value cannot be empty", "domainPart"); } this.domainPart = domainPart; this.accountPart = accountPart; string address; if (string.IsNullOrWhiteSpace(tagPart)) { this.tagPart = null; this.localPart = accountPart; address = accountPart + "@" + domainPart; } else { this.tagPart = tagPart.Trim(); this.localPart = accountPart + "+" + this.tagPart; address = accountPart + "+" + tagPart + "@" + domainPart; } address = Validate.EmailAddress(address); if (address == null) { throw new ArgumentException("Invalid email address", "address"); } this.address = address; }