private void SetUserAgentHeader(
string applicationName,
string applicationVersion,
string programmingLanguage,
params string[] additionalNameValuePairs)
{
if (applicationName == null)
{
throw new ArgumentNullException("applicationName", "Value cannot be null.");
}
if (applicationVersion == null)
{
throw new ArgumentNullException("applicationVersion", "Value cannot be null.");
}
if (programmingLanguage == null)
{
throw new ArgumentNullException("programmingLanguage", "Value cannot be null.");
}
if (additionalNameValuePairs.Length % 2 != 0)
{
throw new ArgumentException("additionalNameValuePairs", "Every name must have a corresponding value.");
}
StringBuilder sb = new StringBuilder();
sb.Append(QuoteApplicationName(applicationName));
sb.Append("/");
sb.Append(QuoteApplicationVersion(applicationVersion));
sb.Append(" (");
sb.Append("Language=");
sb.Append(QuoteAttributeValue(programmingLanguage));
int i = 0;
while (i < additionalNameValuePairs.Length)
{
string name = additionalNameValuePairs[i];
string value = additionalNameValuePairs[++i];
sb.Append("; ");
sb.Append(QuoteAttributeName(name));
sb.Append("=");
sb.Append(QuoteAttributeValue(value));
i++;
}
sb.Append(")");
this.userAgent = sb.ToString();
}