/// <summary> /// Helper method for validating if the username is in correct UPN format. /// </summary> /// <param name="userName">username to check.</param> internal void ValidateUserName(string userName, out UserNameFormat userNameFormat) { try { ValidateEmailAddress(userName); userNameFormat = UserNameFormat.EmailAddress; } catch { Regex samAccountNameRegex = new Regex(".+\\\\.+"); Match samAccountMatch = samAccountNameRegex.Match(userName); if (samAccountMatch.Success) userNameFormat = UserNameFormat.SamAccountName; else throw new InvalidOperationException(String.Format("Provided username '{0}' is not in correct format. Please use one of the following format: 'domain\\username' or '*****@*****.**'", userName)); } }
/// <summary> /// Constructor. Initilialize new instance of <see ref="UserName"/>. /// </summary> /// <param name="name">UserName name in specific format.</param> /// <param name="userNameFormat">Format of user name.</param> public UserName(string name, UserNameFormat userNameFormat) { Name = name; Format = userNameFormat; }