2 // MemoryCacheSettingsCollection.cs
5 // Marek Habersack <mhabersack@novell.com>
7 // Copyright (C) 2010 Novell, Inc. (http://novell.com/)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Configuration;
31 namespace System.Runtime.Caching.Configuration
33 [ConfigurationCollection (typeof(MemoryCacheElement), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
34 public sealed class MemoryCacheSettingsCollection : ConfigurationElementCollection
36 static ConfigurationPropertyCollection properties;
38 public override ConfigurationElementCollectionType CollectionType {
39 get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
42 public MemoryCacheElement this[int index] {
43 get { return BaseGet (index) as MemoryCacheElement; }
45 if (BaseGet (index) != null)
47 BaseAdd (index, value);
51 public new MemoryCacheElement this[string key] {
53 foreach (MemoryCacheElement mce in this) {
54 if (String.Compare (key, mce.Name, StringComparison.Ordinal) == 0)
62 protected override ConfigurationPropertyCollection Properties {
63 get { return properties; }
66 static MemoryCacheSettingsCollection ()
68 properties = new ConfigurationPropertyCollection ();
71 public MemoryCacheSettingsCollection ()
75 public void Add (MemoryCacheElement cache)
85 protected override ConfigurationElement CreateNewElement ()
87 return new MemoryCacheElement ();
90 protected override ConfigurationElement CreateNewElement (string elementName)
92 return new MemoryCacheElement (elementName);
95 protected override object GetElementKey (ConfigurationElement element)
100 return ((MemoryCacheElement)element).Name;
103 public int IndexOf (MemoryCacheElement cache)
108 return BaseIndexOf (cache);
111 public void Remove (MemoryCacheElement cache)
116 BaseRemove (GetElementKey (cache));
119 public void RemoveAt (int index)
121 BaseRemoveAt (index);