System.Net.Mime.HeaderCollection.Set C# (CSharp) Method

Set() public method

public Set ( string name, string value ) : void
name string
value string
return void
        public override void Set(string name, string value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (name == string.Empty)
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name));
            }

            if (value == string.Empty)
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(value)), nameof(name));
            }

            if (!MimeBasePart.IsAscii(name, false))
            {
                throw new FormatException(SR.Format(SR.InvalidHeaderName));
            }

            // normalize the case of well known headers
            name = MailHeaderInfo.NormalizeCase(name);

            MailHeaderID id = MailHeaderInfo.GetID(name);

            value = value.Normalize(NormalizationForm.FormC);

            if (id == MailHeaderID.ContentType && _part != null)
            {
                _part.ContentType.Set(value.ToLower(CultureInfo.InvariantCulture), this);
            }
            else if (id == MailHeaderID.ContentDisposition && _part is MimePart)
            {
                ((MimePart)_part).ContentDisposition.Set(value.ToLower(CultureInfo.InvariantCulture), this);
            }
            else
            {
                base.Set(name, value);
            }
        }

Usage Example

 internal void EncodeHeaders(HeaderCollection headers)
 {
     if (this.headersEncoding == null)
     {
         this.headersEncoding = Encoding.GetEncoding("utf-8");
     }
     for (int i = 0; i < headers.Count; i++)
     {
         string key = headers.GetKey(i);
         if (MailHeaderInfo.IsUserSettable(key))
         {
             string[] values = headers.GetValues(key);
             string str2 = string.Empty;
             for (int j = 0; j < values.Length; j++)
             {
                 if (MimeBasePart.IsAscii(values[j], false))
                 {
                     str2 = values[j];
                 }
                 else
                 {
                     str2 = MimeBasePart.EncodeHeaderValue(values[j], this.headersEncoding, MimeBasePart.ShouldUseBase64Encoding(this.headersEncoding), key.Length);
                 }
                 if (j == 0)
                 {
                     headers.Set(key, str2);
                 }
                 else
                 {
                     headers.Add(key, str2);
                 }
             }
         }
     }
 }
All Usage Examples Of System.Net.Mime.HeaderCollection::Set