/// <summary> /// Adds a parameter. /// </summary> /// <param name="name">The parameter name.</param> /// <param name="value">The parameter value.</param> /// <returns>The current instance, which allows chaining calls.</returns> public OpenIdConnectMessage AddParameter([NotNull] string name, OpenIdConnectParameter value) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("The parameter name cannot be null or empty.", nameof(name)); } if (!Parameters.ContainsKey(name)) { Parameters.Add(name, value); } return(this); }
/// <summary> /// Adds, replaces or removes a parameter. /// Note: this method automatically removes empty parameters. /// </summary> /// <param name="name">The parameter name.</param> /// <param name="value">The parameter value.</param> /// <returns>The current instance, which allows chaining calls.</returns> public OpenIdConnectMessage SetParameter([NotNull] string name, [CanBeNull] OpenIdConnectParameter?value) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("The parameter name cannot be null or empty.", nameof(name)); } // If the parameter value is null or empty, // remove the corresponding entry from the collection. if (value == null || OpenIdConnectParameter.IsNullOrEmpty(value.GetValueOrDefault())) { Parameters.Remove(name); } else { Parameters[name] = value.GetValueOrDefault(); } return(this); }