forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebConfigScopeStorageDictionary.cs
More file actions
126 lines (105 loc) · 3.46 KB
/
WebConfigScopeStorageDictionary.cs
File metadata and controls
126 lines (105 loc) · 3.46 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web.Configuration;
using System.Web.WebPages.Resources;
namespace System.Web.WebPages.Scope
{
internal class WebConfigScopeDictionary : IDictionary<object, object>
{
private readonly Lazy<Dictionary<object, object>> _items;
public WebConfigScopeDictionary()
: this(WebConfigurationManager.AppSettings)
{
}
public WebConfigScopeDictionary(NameValueCollection appSettings)
{
_items = new Lazy<Dictionary<object, object>>(() =>
{
Dictionary<object, object> items = new Dictionary<object, object>(ScopeStorageComparer.Instance);
foreach (string key in appSettings.AllKeys)
{
items[key] = appSettings[key];
}
return items;
});
}
private IDictionary<object, object> Items
{
get { return _items.Value; }
}
public ICollection<object> Keys
{
get { return Items.Keys; }
}
public ICollection<object> Values
{
get { return Items.Values; }
}
public int Count
{
get { return Items.Count; }
}
public bool IsReadOnly
{
get { return true; }
}
public object this[object key]
{
get
{
object value;
TryGetValue(key, out value);
return value;
}
set { throw new NotSupportedException(WebPageResources.StateStorage_ScopeIsReadOnly); }
}
public bool TryGetValue(object key, out object value)
{
return Items.TryGetValue(key, out value);
}
public IEnumerator<KeyValuePair<object, object>> GetEnumerator()
{
return Items.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Add(object key, object value)
{
throw new NotSupportedException(WebPageResources.StateStorage_ScopeIsReadOnly);
}
public bool ContainsKey(object key)
{
return Items.ContainsKey(key);
}
public bool Remove(object key)
{
throw new NotSupportedException(WebPageResources.StateStorage_ScopeIsReadOnly);
}
public void Add(KeyValuePair<object, object> item)
{
throw new NotSupportedException(WebPageResources.StateStorage_ScopeIsReadOnly);
}
public void Clear()
{
throw new NotSupportedException(WebPageResources.StateStorage_ScopeIsReadOnly);
}
public bool Contains(KeyValuePair<object, object> item)
{
return Items.Contains(item);
}
public void CopyTo(KeyValuePair<object, object>[] array, int arrayIndex)
{
Items.CopyTo(array, arrayIndex);
}
public bool Remove(KeyValuePair<object, object> item)
{
throw new NotSupportedException(WebPageResources.StateStorage_ScopeIsReadOnly);
}
}
}