/// <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); } }
protected override void ProcessRecord() { var impresult = CurrentImpConnection.Instance.RosterClient.Execute(client => { var req = new addContactReq { contact = Contact, groupName = Group, userJid = Owner }; if (Nickname.HasValue()) { req.nickName = Nickname; } return(client.addContact(req)); }); impresult.Exception.ThrowIfNotNull(); WriteObject(impresult.Value); }
/// <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="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 = false, bool includeNickname = false, bool lastFirst = true) { StringBuilder sb = new StringBuilder(); if (lastFirst) { if (Last.HasValue()) { sb.Append(Last); sb.Append(COMMA); } if (includePrefix && Prefix.HasValue()) { sb.Append(SPACE); 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 (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().Replace(" ,", ","); while (res.EndsWith(",")) { res = res.Substring(0, res.Length - 1); } while (res.Contains(" ")) { res = res.Replace(" ", " "); } return(res.Trim()); }