forked from sebastienros/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FiltersCollection.cs
64 lines (52 loc) · 1.54 KB
/
FiltersCollection.cs
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
using System.Collections;
using System.Collections.Generic;
namespace Fluid
{
public class FilterCollection : IEnumerable<KeyValuePair<string, FilterDelegate>>
{
private Dictionary<string, FilterDelegate> _filters;
public FilterCollection(int capacity = 0)
{
if (capacity != 0)
{
_filters = new Dictionary<string, FilterDelegate>(capacity);
}
}
public int Count => _filters == null ? 0 : _filters.Count;
#if NETSTANDARD2_1
public void EnsureCapacity(int capacity) => _filters.EnsureCapacity(capacity);
#endif
public void AddFilter(string name, FilterDelegate d)
{
_filters ??= new Dictionary<string, FilterDelegate>();
_filters[name] = d;
}
public bool TryGetValue(string name, out FilterDelegate filter)
{
filter = null;
return _filters != null && _filters.TryGetValue(name, out filter);
}
public void Remove(string name)
{
if (_filters != null)
{
_filters.Remove(name);
}
}
public void Clear()
{
if (_filters != null)
{
_filters.Clear();
}
}
public IEnumerator<KeyValuePair<string, FilterDelegate>> GetEnumerator()
{
return _filters.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _filters.GetEnumerator();
}
}
}