-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathHeaderCollection.cs
More file actions
65 lines (58 loc) · 1.84 KB
/
Copy pathHeaderCollection.cs
File metadata and controls
65 lines (58 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Collections.Generic;
namespace PostmarkDotNet.Model
{
public class MailHeader {
public MailHeader(string name = null, string value = null)
{
Name = name;
Value = value;
}
public string Name { get; set; }
public string Value { get; set; }
}
public class HeaderCollection: List<MailHeader>, ICollection<MailHeader>
{
public HeaderCollection() : base() { }
public HeaderCollection(IDictionary<string, string> nameValues = null)
{
if (nameValues != null)
{
foreach (var f in (nameValues)){
this.Add(new MailHeader(f.Key, f.Value));
}
}
}
public HeaderCollection(IEnumerable<MailHeader> nameValues = null)
{
if (nameValues != null)
{
this.AddRange(nameValues);
}
}
// Enables collection initializer syntax: Headers = new HeaderCollection { {"key","value"} }
public void Add(string name, string value)
{
this.Add(new MailHeader(name, value));
}
/// <summary>
/// Get the names associated with this collection. This property does not cache
/// its results, so be aware that iterating over it multiple times will iterate over
/// all elements of the collection each time.
/// </summary>
public IEnumerable<string> Keys
{
get
{
var keys = new List<string>(this.Capacity);
foreach(var f in this)
{
if (!keys.Contains(f.Name))
{
keys.Add(f.Name);
}
}
return keys;
}
}
}
}