/// <summary> /// Construct a constraint with optional arguments /// </summary> /// <param name="args">Arguments to be saved</param> protected Constraint(params object[] args) { Arguments = args; DisplayName = this.GetType().Name; if (DisplayName.EndsWith("`1") || DisplayName.EndsWith("`2")) { DisplayName = DisplayName.Substring(0, DisplayName.Length - 2); } if (DisplayName.EndsWith("Constraint")) { DisplayName = DisplayName.Substring(0, DisplayName.Length - 10); } }
private void Parse(string rawAddress) { if (rawAddress == null) { throw new ArgumentNullException("rawAddress"); } rawAddress = rawAddress.Trim(); var extendedPartIndex = rawAddress.IndexOf("|", StringComparison.InvariantCultureIgnoreCase); if (extendedPartIndex > -1) { var extendedPart = rawAddress.Substring(extendedPartIndex); var parts = extendedPart.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 0) { AvatarUrl = parts[0]; } if (parts.Length > 1) { ChannelName = parts[1]; } // Remove extended part from rawAddress and continue parsing rawAddress = rawAddress.Substring(0, extendedPartIndex); } if (rawAddress.Contains("<") && rawAddress.Contains(">")) { string[] parts = rawAddress.Split(new[] { '<', '>' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 1) { this.Address = parts[0]; this.DisplayName = parts[0]; // See if the displayname is quoted, if so, remove the quotes if (DisplayName.StartsWith("\"") && DisplayName.EndsWith("\"")) { DisplayName = DisplayName.Substring(1, DisplayName.Length - 2); } } if (parts.Length == 2) { this.DisplayName = parts[0].Trim(); this.Address = parts[1].Trim(); // Can happen when you receive addresses like " <*****@*****.**>" (space in the beginning) if (String.IsNullOrEmpty(this.DisplayName)) { this.DisplayName = this.Address; } // See if the displayname is quoted, if so, remove the quotes if (DisplayName.StartsWith("\"") && DisplayName.EndsWith("\"")) { DisplayName = DisplayName.Substring(1, DisplayName.Length - 2); } return; } } else { this.DisplayName = rawAddress; this.Address = rawAddress; } if (String.IsNullOrEmpty(Address)) { this.Address = rawAddress; } }