Esempio n. 1
0
 /// <summary>
 /// Override of the <see cref="Object.GetHashCode"/> Method.
 /// </summary>
 /// <returns>A Hash-Code suitable for use in hashtables.</returns>
 /// <remarks>Only considers the First, Middle, and Last names; ignores other fields.</remarks>
 public override int GetHashCode()
 {
     unchecked {
         int hash = 17;
         hash = hash * 23 + (First.HasValue() ? First.GetHashCode() : 0);
         hash = hash * 23 + (Last.HasValue() ? Last.GetHashCode() : 0);
         hash = hash * 23 + (Middle.HasValue() ? Middle.GetHashCode() : 0);
         return(hash);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Indexer for name properties.
        /// </summary>
        /// <param name="name">The name property to get or set.</param>
        /// <returns>The value of the name property.</returns>
        public string this[PersonalNameProperties name] {
            get {
                switch (name)
                {
                case PersonalNameProperties.First: return(First.HasValue() ? First : string.Empty);

                case PersonalNameProperties.Last: return(Last.HasValue() ? Last : string.Empty);

                case PersonalNameProperties.Middle: return(Middle.HasValue() ? Middle : string.Empty);

                case PersonalNameProperties.Nickname: return(Nickname.HasValue() ? Nickname : string.Empty);

                case PersonalNameProperties.Prefix: return(Prefix.HasValue() ? Prefix : string.Empty);

                case PersonalNameProperties.Suffix: return(Suffix.HasValue() ? Suffix : string.Empty);

                default: return(string.Empty);
                }
            }
            set {
                switch (name)
                {
                case PersonalNameProperties.First:
                    First = value.HasValue() ? value.Trim() : string.Empty;
                    break;

                case PersonalNameProperties.Last:
                    Last = value.HasValue() ? value.Trim() : string.Empty;
                    break;

                case PersonalNameProperties.Middle:
                    Middle = value.HasValue() ? value.Trim() : string.Empty;
                    break;

                case PersonalNameProperties.Nickname:
                    Nickname = value.HasValue() ? value.Trim() : string.Empty;
                    break;

                case PersonalNameProperties.Prefix:
                    Prefix = value.HasValue() ? value.Trim() : string.Empty;
                    break;

                case PersonalNameProperties.Suffix:
                    Suffix = value.HasValue() ? value.Trim() : string.Empty;
                    break;

                default: break;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the initials from the name
        /// </summary>
        /// <param name="maxLength">The maximum number of characters to include in the initials.</param>
        /// <returns>The initials from the name.</returns>
        public string ToInitials(int maxLength = 3)
        {
            StringBuilder sb = new StringBuilder();

            if (First.HasValue())
            {
                sb.Append(First[0]);
            }
            if (Middle.HasValue())
            {
                if (Middle.Contains(" "))
                {
                    foreach (var v in splitText(Middle))
                    {
                        sb.Append(v.Trim()[0]);
                    }
                }
                else
                {
                    sb.Append(Middle[0]);
                }
            }
            if (Last.HasValue())
            {
                if (Last.Contains(" "))
                {
                    foreach (var v in splitText(Last))
                    {
                        sb.Append(v.Trim()[0]);
                    }
                }
            }
            else
            {
                sb.Append(Last[0]);
            }

            if (maxLength < 2)
            {
                maxLength = 2;
            }
            if (sb.Length > maxLength)
            {
                while (sb.Length > maxLength)
                {
                    sb.Remove(1, 1);
                }
            }
            return(sb.ToString());
        }
Esempio n. 4
0
        /// <summary>
        /// Get the value of the specified name property
        /// </summary>
        /// <param name="name">The name property to retrieve</param>
        /// <param name="maxLen">The maximum length of the value to return. If the actual value is longer, it is <see cref="TextExtensions.Truncate(string, int)"/>d to the specified length.</param>
        /// <returns>Either <see cref="string.Empty"/> (for null or empty values) or the value of the name property truncated to the specified maxLen (if applicable).</returns>
        public string GetValue(PersonalNameProperties name, int maxLen = 50)
        {
            switch (name)
            {
            case PersonalNameProperties.First: return(First.HasValue() ? First.Truncate(maxLen) : string.Empty);

            case PersonalNameProperties.Last: return(Last.HasValue() ? Last.Truncate(maxLen) : string.Empty);

            case PersonalNameProperties.Middle: return(Middle.HasValue() ? Middle.Truncate(maxLen) : string.Empty);

            case PersonalNameProperties.Nickname: return(Nickname.HasValue() ? Nickname.Truncate(maxLen) : string.Empty);

            case PersonalNameProperties.Prefix: return(Prefix.HasValue() ? Prefix.Truncate(maxLen) : string.Empty);

            case PersonalNameProperties.Suffix: return(Suffix.HasValue() ? Suffix.Truncate(50) : string.Empty);

            default: return(string.Empty);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Build a person's formatted full name for display using the provided criteria.
        /// </summary>
        /// <param name="orgName">The name of the organization the person is primarily associated with.</param>
        /// <param name="includeMiddle">Should the middle name(s) be included in the result?</param>
        /// <param name="includePrefix">Should the honorific prefix be included in the result?</param>
        /// <param name="includeSuffix">Should the honorific suffix be included in the result?</param>
        /// <param name="includeNickname">Should the nickname be included in the result?</param>
        /// <param name="lastFirst">Should the last/family name be listed first?</param>
        /// <returns>The full name as computed from the provided criteria.</returns>
        public string ToFullName(string orgName = null, bool includeMiddle = false, bool includePrefix = false, bool includeSuffix = true, bool includeNickname = true, bool lastFirst = true)
        {
            StringBuilder sb = new StringBuilder();

            if (lastFirst)
            {
                if (Last.HasValue())
                {
                    sb.Append(Last);
                    sb.Append(COMMA);
                }
                if (First.HasValue())
                {
                    sb.Append(First);
                    sb.Append(SPACE);
                }
                if (includeNickname && Nickname.HasValue())
                {
                    sb.Append(QUOTE1);
                    sb.Append(Nickname);
                    sb.Append(QUOTE2);
                }
                if (includeMiddle && Middle.HasValue())
                {
                    sb.Append(Middle);
                    sb.Append(SPACE);
                }
                if (includePrefix && Prefix.HasValue())
                {
                    sb.Append(PAREN1);
                    sb.Append(Prefix);
                    sb.Append(PAREN2);
                }
                if (includeSuffix && Suffix.HasValue())
                {
                    sb.Append(COMMA);
                    sb.Append(Suffix);
                }
            }
            else
            {
                if (includePrefix && Prefix.HasValue())
                {
                    sb.Append(Prefix);
                    sb.Append(SPACE);
                }
                if (First.HasValue())
                {
                    sb.Append(First);
                    sb.Append(SPACE);
                }
                if (includeNickname && Nickname.HasValue())
                {
                    sb.Append(QUOTE1);
                    sb.Append(Nickname);
                    sb.Append(QUOTE2);
                }
                if (includeMiddle && Middle.HasValue())
                {
                    sb.Append(Middle);
                    sb.Append(SPACE);
                }
                if (Last.HasValue())
                {
                    sb.Append(Last);
                }
                if (includeSuffix && Suffix.HasValue())
                {
                    sb.Append(COMMA);
                    sb.Append(Suffix);
                }
            }

            if (orgName.HasValue())
            {
                sb.Append(SPACE);
                sb.Append(PAREN1);
                sb.Append(orgName);
                sb.Append(PAREN2);
            }

            string res = sb.ToString().Trim();

            while (res.EndsWith(","))
            {
                res = res.Substring(0, res.Length - 1);
            }
            return(res);
        }