File: PersonalizationDictionary.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (188 lines) | stat: -rw-r--r-- 6,305 bytes parent folder | download | duplicates (7)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//------------------------------------------------------------------------------
// <copyright file="PersonalizationDictionary.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Web.UI.WebControls.WebParts {

    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Web.Util;

    // This class is unsealed so it can be extended by developers who extend the personalization infrastructure
    public class PersonalizationDictionary : IDictionary {
        private HybridDictionary _dictionary;

        public PersonalizationDictionary() {
            _dictionary = new HybridDictionary(/* caseInsensitive */ true);
        }

        public PersonalizationDictionary(int initialSize) {
            _dictionary = new HybridDictionary(initialSize, /* caseInsensitive */ true);
        }

        public virtual int Count {
            get {
                return _dictionary.Count;
            }
        }

        public virtual bool IsFixedSize {
            get {
                return false;
            }
        }

        public virtual bool IsReadOnly {
            get {
                return false;
            }
        }

        public virtual bool IsSynchronized {
            get {
                return false;
            }
        }

        public virtual ICollection Keys {
            get {
                return _dictionary.Keys;
            }
        }

        public virtual object SyncRoot {
            get {
                return this;
            }
        }

        public virtual ICollection Values {
            get {
                return _dictionary.Values;
            }
        }

        public virtual PersonalizationEntry this[string key] {
            get{
                key = StringUtil.CheckAndTrimString(key, "key");
                return (PersonalizationEntry)_dictionary[key];
            }
            set {
                key = StringUtil.CheckAndTrimString(key, "key");
                if (value == null) {
                    throw new ArgumentNullException("value");
                }
                _dictionary[key] = value;
            }
        }

        public virtual void Add(string key, PersonalizationEntry value) {
            key = StringUtil.CheckAndTrimString(key, "key");
            if (value == null) {
                throw new ArgumentNullException("value");
            }
            _dictionary.Add(key, value);
        }

        public virtual void Clear() {
            _dictionary.Clear();
        }

        public virtual bool Contains(string key) {
            key = StringUtil.CheckAndTrimString(key, "key");
            return _dictionary.Contains(key);
        }

        public virtual void CopyTo(DictionaryEntry[] array, int index) {
            _dictionary.CopyTo(array, index);
        }

        public virtual IDictionaryEnumerator GetEnumerator() {
            return _dictionary.GetEnumerator();
        }

        public virtual void Remove(string key) {
            key = StringUtil.CheckAndTrimString(key, "key");
            _dictionary.Remove(key);
        }

        internal void RemoveSharedProperties() {
            DictionaryEntry[] entries = new DictionaryEntry[Count];
            CopyTo(entries, 0);
            foreach (DictionaryEntry entry in entries) {
                if (((PersonalizationEntry)entry.Value).Scope == PersonalizationScope.Shared) {
                    Remove((string)entry.Key);
                }
            }
        }

        #region Implementation of IDictionary
        object IDictionary.this[object key] {
            get {
                if (!(key is string)) {
                    throw new ArgumentException(SR.GetString(SR.PersonalizationDictionary_MustBeTypeString), "key");
                }
                return this[(string)key];
            }
            set {
                if (value == null) {
                    throw new ArgumentNullException("value");
                }
                if (!(key is string)) {
                    throw new ArgumentException(SR.GetString(SR.PersonalizationDictionary_MustBeTypeString), "key");
                }
                if (!(value is PersonalizationEntry)) {
                    throw new ArgumentException(SR.GetString(SR.PersonalizationDictionary_MustBeTypePersonalizationEntry), "value");
                }
                this[(string)key] = (PersonalizationEntry)value;
            }
        }

        void IDictionary.Add(object key, object value) {
            if (value == null) {
                throw new ArgumentNullException("value");
            }
            if (!(key is string)) {
                throw new ArgumentException(SR.GetString(SR.PersonalizationDictionary_MustBeTypeString), "key");
            }
            if (!(value is PersonalizationEntry)) {
                throw new ArgumentException(SR.GetString(SR.PersonalizationDictionary_MustBeTypePersonalizationEntry), "value");
            }
            Add((string)key, (PersonalizationEntry)value);
        }

        bool IDictionary.Contains(object key) {
            if (!(key is string)) {
                throw new ArgumentException(SR.GetString(SR.PersonalizationDictionary_MustBeTypeString), "key");
            }
            return Contains((string)key);
        }

        void IDictionary.Remove(object key) {
            if (!(key is string)) {
                throw new ArgumentException(SR.GetString(SR.PersonalizationDictionary_MustBeTypeString), "key");
            }
            Remove((string)key);
        }
        #endregion

        #region Implementation of ICollection
        void ICollection.CopyTo(Array array, int index) {
            if (!(array is DictionaryEntry[])) {
                throw new ArgumentException(
                    SR.GetString(SR.PersonalizationDictionary_MustBeTypeDictionaryEntryArray), "array");
            }
            CopyTo((DictionaryEntry[])array, index);
        }
        #endregion

        #region Implementation of IEnumerable
        IEnumerator IEnumerable.GetEnumerator() {
            return GetEnumerator();
        }
        #endregion
    }
}