Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ReadOnlyDictionary.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 
6 namespace SiliconStudio.Core.Collections
7 {
8  /// <summary>
9  /// Read-only dictionary wrapper.
10  /// </summary>
11  /// <typeparam name="TKey">The type of the key.</typeparam>
12  /// <typeparam name="TValue">The type of the value.</typeparam>
13  public class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
14  {
15  private readonly IDictionary<TKey, TValue> dictionary;
16 
17  /// <summary>
18  /// Initializes a new instance of the <see cref="ReadOnlyDictionary&lt;TKey, TValue&gt;"/> class.
19  /// </summary>
20  /// <param name="dictionary">The dictionary.</param>
22  {
23  this.dictionary = dictionary;
24  }
25 
26  /// <inheritdoc/>
27  public ICollection<TKey> Keys
28  {
29  get { return dictionary.Keys; }
30  }
31 
32  /// <inheritdoc/>
33  public ICollection<TValue> Values
34  {
35  get { return dictionary.Values; }
36  }
37 
38  /// <inheritdoc/>
39  public int Count
40  {
41  get { return dictionary.Count; }
42  }
43 
44  /// <inheritdoc/>
45  public bool IsReadOnly
46  {
47  get { return true; }
48  }
49 
50  /// <inheritdoc/>
51  public TValue this[TKey key]
52  {
53  get { return dictionary[key]; }
54  set { throw new NotSupportedException("Read-only dictionary"); }
55  }
56 
57  /// <inheritdoc/>
58  public void Add(TKey key, TValue value)
59  {
60  throw new NotSupportedException("Read-only dictionary");
61  }
62 
63  /// <inheritdoc/>
64  public bool ContainsKey(TKey key)
65  {
66  return dictionary.ContainsKey(key);
67  }
68 
69  /// <inheritdoc/>
70  public bool Remove(TKey key)
71  {
72  throw new NotSupportedException("Read-only dictionary");
73  }
74 
75  /// <inheritdoc/>
76  public bool TryGetValue(TKey key, out TValue value)
77  {
78  return dictionary.TryGetValue(key, out value);
79  }
80 
81  /// <inheritdoc/>
82  public void Add(KeyValuePair<TKey, TValue> item)
83  {
84  throw new NotSupportedException("Read-only dictionary");
85  }
86 
87  /// <inheritdoc/>
88  public void Clear()
89  {
90  throw new NotSupportedException("Read-only dictionary");
91  }
92 
93  /// <inheritdoc/>
94  public bool Contains(KeyValuePair<TKey, TValue> item)
95  {
96  return dictionary.Contains(item);
97  }
98 
99  /// <inheritdoc/>
100  public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
101  {
102  dictionary.CopyTo(array, arrayIndex);
103  }
104 
105  /// <inheritdoc/>
106  public bool Remove(KeyValuePair<TKey, TValue> item)
107  {
108  throw new NotSupportedException("Read-only dictionary");
109  }
110 
111  /// <inheritdoc/>
112  public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
113  {
114  return dictionary.GetEnumerator();
115  }
116 
117  /// <inheritdoc/>
118  System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
119  {
120  return dictionary.GetEnumerator();
121  }
122  }
123 }
Keys
Enumeration for keys.
Definition: Keys.cs:8
SiliconStudio.Paradox.Input.Keys Keys
void CopyTo(KeyValuePair< TKey, TValue >[] array, int arrayIndex)
IEnumerator< KeyValuePair< TKey, TValue > > GetEnumerator()
ReadOnlyDictionary(IDictionary< TKey, TValue > dictionary)
Initializes a new instance of the ReadOnlyDictionary<TKey, TValue> class.