diff options
author | natrixaeria <janng@gmx.de> | 2019-05-19 17:40:59 +0200 |
---|---|---|
committer | natrixaeria <janng@gmx.de> | 2019-05-19 17:40:59 +0200 |
commit | 1509b5ef3d7e9e71d9294e234ec0e39f2d831998 (patch) | |
tree | 78300ffff230958101b422a4e6026925b287822f /FireBase/Offline/OfflineCacheAdapter.cs | |
parent | c3bb858bb54dc8c64bbd48054c2c58dc0073f09c (diff) | |
parent | c4d046858e0822b7c2c540ac2368b2c0e88e7a26 (diff) |
Merge branch 'scribble' of https://github.com/TrueDoctor/DiscoBot into scribble
Diffstat (limited to 'FireBase/Offline/OfflineCacheAdapter.cs')
-rw-r--r-- | FireBase/Offline/OfflineCacheAdapter.cs | 115 |
1 files changed, 51 insertions, 64 deletions
diff --git a/FireBase/Offline/OfflineCacheAdapter.cs b/FireBase/Offline/OfflineCacheAdapter.cs index a3761a0..3153d1b 100644 --- a/FireBase/Offline/OfflineCacheAdapter.cs +++ b/FireBase/Offline/OfflineCacheAdapter.cs @@ -1,11 +1,11 @@ -namespace Firebase.Database.Offline -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.Linq; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; - internal class OfflineCacheAdapter<TKey, T> : IDictionary<string, T>, IDictionary +namespace Firebase.Database.Offline +{ + internal class OfflineCacheAdapter<TKey, T> : IDictionary<string, T>, IDictionary { private readonly IDictionary<string, OfflineEntry> database; @@ -19,66 +19,32 @@ throw new NotImplementedException(); } - public int Count => this.database.Count; - public bool IsSynchronized { get; } public object SyncRoot { get; } - public bool IsReadOnly => this.database.IsReadOnly; - object IDictionary.this[object key] { - get - { - return this.database[key.ToString()].Deserialize<T>(); - } + get => database[key.ToString()].Deserialize<T>(); set { var keyString = key.ToString(); - if (this.database.ContainsKey(keyString)) - { - this.database[keyString] = new OfflineEntry(keyString, value, this.database[keyString].Priority, this.database[keyString].SyncOptions); - } + if (database.ContainsKey(keyString)) + database[keyString] = new OfflineEntry(keyString, value, database[keyString].Priority, + database[keyString].SyncOptions); else - { - this.database[keyString] = new OfflineEntry(keyString, value, 1, SyncOptions.None); - } + database[keyString] = new OfflineEntry(keyString, value, 1, SyncOptions.None); } } - public ICollection<string> Keys => this.database.Keys; - ICollection IDictionary.Values { get; } ICollection IDictionary.Keys { get; } - public ICollection<T> Values => this.database.Values.Select(o => o.Deserialize<T>()).ToList(); - - public T this[string key] - { - get - { - return this.database[key].Deserialize<T>(); - } - - set - { - if (this.database.ContainsKey(key)) - { - this.database[key] = new OfflineEntry(key, value, this.database[key].Priority, this.database[key].SyncOptions); - } - else - { - this.database[key] = new OfflineEntry(key, value, 1, SyncOptions.None); - } - } - } - public bool Contains(object key) { - return this.ContainsKey(key.ToString()); + return ContainsKey(key.ToString()); } IDictionaryEnumerator IDictionary.GetEnumerator() @@ -88,39 +54,60 @@ public void Remove(object key) { - this.Remove(key.ToString()); + Remove(key.ToString()); } public bool IsFixedSize => false; - public IEnumerator<KeyValuePair<string, T>> GetEnumerator() + public void Add(object key, object value) { - return this.database.Select(d => new KeyValuePair<string, T>(d.Key, d.Value.Deserialize<T>())).GetEnumerator(); + Add(key.ToString(), (T) value); } - IEnumerator IEnumerable.GetEnumerator() + public int Count => database.Count; + + public bool IsReadOnly => database.IsReadOnly; + + public ICollection<string> Keys => database.Keys; + + public ICollection<T> Values => database.Values.Select(o => o.Deserialize<T>()).ToList(); + + public T this[string key] + { + get => database[key].Deserialize<T>(); + + set + { + if (database.ContainsKey(key)) + database[key] = new OfflineEntry(key, value, database[key].Priority, database[key].SyncOptions); + else + database[key] = new OfflineEntry(key, value, 1, SyncOptions.None); + } + } + + public IEnumerator<KeyValuePair<string, T>> GetEnumerator() { - return this.GetEnumerator(); + return database.Select(d => new KeyValuePair<string, T>(d.Key, d.Value.Deserialize<T>())).GetEnumerator(); } - public void Add(KeyValuePair<string, T> item) + IEnumerator IEnumerable.GetEnumerator() { - this.Add(item.Key, item.Value); + return GetEnumerator(); } - public void Add(object key, object value) + public void Add(KeyValuePair<string, T> item) { - this.Add(key.ToString(), (T)value); + Add(item.Key, item.Value); } public void Clear() { - this.database.Clear(); + database.Clear(); } public bool Contains(KeyValuePair<string, T> item) { - return this.ContainsKey(item.Key); + return ContainsKey(item.Key); } public void CopyTo(KeyValuePair<string, T>[] array, int arrayIndex) @@ -130,29 +117,29 @@ public bool Remove(KeyValuePair<string, T> item) { - return this.database.Remove(item.Key); + return database.Remove(item.Key); } public void Add(string key, T value) { - this.database.Add(key, new OfflineEntry(key, value, 1, SyncOptions.None)); + database.Add(key, new OfflineEntry(key, value, 1, SyncOptions.None)); } public bool ContainsKey(string key) { - return this.database.ContainsKey(key); + return database.ContainsKey(key); } public bool Remove(string key) { - return this.database.Remove(key); + return database.Remove(key); } public bool TryGetValue(string key, out T value) { OfflineEntry val; - if (this.database.TryGetValue(key, out val)) + if (database.TryGetValue(key, out val)) { value = val.Deserialize<T>(); return true; @@ -162,4 +149,4 @@ return false; } } -} +}
\ No newline at end of file |