示例#1
0
 /// <summary>
 /// Throws <see cref="ArgumentException"/> if email address not valid.
 /// </summary>
 /// <param name="emailAddress">Email address to validate.</param>
 internal static void ThrowIfInvalid(string emailAddress)
 {
     if (!EmailAddressValidator.IsValid(emailAddress))
     {
         throw new ArgumentException("Specified string is not valid email address.", emailAddress);
     }
 }
        /// <inheritdoc cref="BaseFilterFormatter.FormatPropertyName"/>
        protected override string FormatPropertyName(string obj, PropertyDefinition propertyDefinition)
        {
            if (EmailAddressValidator.IsValid(obj))
            {
                return($"{propertyDefinition.Name}/EmailAddress/Address");
            }

            return($"{propertyDefinition.Name}/EmailAddress/Name");
        }
示例#3
0
        /// <summary>
        /// Create new instance of <see cref="MailboxId"/>.
        /// </summary>
        /// <param name="mailboxId">MailboxId id.</param>
        public MailboxId(string mailboxId)
        {
            if (string.IsNullOrEmpty(mailboxId) ||
                string.Equals(mailboxId, MailboxId.MeKeyword, StringComparison.OrdinalIgnoreCase))
            {
                this.Id = MailboxId.MeKeyword;
            }
            else
            {
                // [email protected]
                if (EmailAddressValidator.IsValid(mailboxId))
                {
                    this.Id = mailboxId;
                }
                else
                {
                    // UserId                               OrgId
                    // 84055e2f-c537-4f66-8ee1-f588abb3232b@d1e69a0e-c0f7-40cb-9973-bb9d5e0c3bcd
                    if (mailboxId.IndexOf('@') > 0)
                    {
                        string[] parts = mailboxId.Split('@');
                        if (parts.Length != 2)
                        {
                            this.ThrowInvalidValue(mailboxId);
                        }

                        Guid id;
                        if (!Guid.TryParse(parts[0], out id))
                        {
                            this.ThrowInvalidValue(mailboxId);
                        }

                        if (!Guid.TryParse(parts[1], out id))
                        {
                            this.ThrowInvalidValue(mailboxId);
                        }
                    }
                    else
                    {
                        this.ThrowInvalidValue(mailboxId);
                    }

                    this.Id = mailboxId;
                }
            }
        }