/// <summary> /// Build a person's formatted full name for display using the provided criteria. /// *ALWAYS* includes first and last name (if present) /// </summary> /// <param name="includedFields">The fields to include.</param> /// <param name="orgName">The name of the organization the person is primarily associated with.</param> /// <param name="lastFirst">Should the last/family name be listed first?</param> /// <returns>The full name as computed from teh provided criteria</returns> public string ToFullName(PersonNameProperties includedFields, string orgName = null, bool lastFirst = true) => ToFullName(orgName, includeMiddle: includedFields.HasFlag(PersonNameProperties.Middle), includePrefix: includedFields.HasFlag(PersonNameProperties.Prefix), includeSuffix: includedFields.HasFlag(PersonNameProperties.Suffix), includeNickname: includedFields.HasFlag(PersonNameProperties.Nickname), lastFirst );
/// <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[PersonNameProperties name] { get { switch (name) { case PersonNameProperties.First: return(First.HasValue() ? First : string.Empty); case PersonNameProperties.Last: return(Last.HasValue() ? Last : string.Empty); case PersonNameProperties.Middle: return(Middle.HasValue() ? Middle : string.Empty); case PersonNameProperties.Nickname: return(Nickname.HasValue() ? Nickname : string.Empty); case PersonNameProperties.Prefix: return(Prefix.HasValue() ? Prefix : string.Empty); case PersonNameProperties.Suffix: return(Suffix.HasValue() ? Suffix : string.Empty); default: return(string.Empty); } } set { switch (name) { case PersonNameProperties.First: First = value.HasValue() ? value.Trim() : string.Empty; break; case PersonNameProperties.Last: Last = value.HasValue() ? value.Trim() : string.Empty; break; case PersonNameProperties.Middle: Middle = value.HasValue() ? value.Trim() : string.Empty; break; case PersonNameProperties.Nickname: Nickname = value.HasValue() ? value.Trim() : string.Empty; break; case PersonNameProperties.Prefix: Prefix = value.HasValue() ? value.Trim() : string.Empty; break; case PersonNameProperties.Suffix: Suffix = value.HasValue() ? value.Trim() : string.Empty; break; default: break; } } }
/// <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(PersonNameProperties name, int maxLen = 50) { switch (name) { case PersonNameProperties.First: return(First.HasValue() ? First.Truncate(maxLen) : string.Empty); case PersonNameProperties.Last: return(Last.HasValue() ? Last.Truncate(maxLen) : string.Empty); case PersonNameProperties.Middle: return(Middle.HasValue() ? Middle.Truncate(maxLen) : string.Empty); case PersonNameProperties.Nickname: return(Nickname.HasValue() ? Nickname.Truncate(maxLen) : string.Empty); case PersonNameProperties.Prefix: return(Prefix.HasValue() ? Prefix.Truncate(maxLen) : string.Empty); case PersonNameProperties.Suffix: return(Suffix.HasValue() ? Suffix.Truncate(50) : string.Empty); default: return(string.Empty); } }