diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-10-23 03:13:09 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-10-23 03:13:09 +0300 |
| commit | 8d2b13aaa70bc6a8f521df4eab165caf078c33fa (patch) | |
| tree | 325567b00d55fa751da7492be067e7878b132e28 /Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs | |
| parent | a79900d579ae9f624b35aa933784e4e0f0c65d03 (diff) | |
| download | Tango-8d2b13aaa70bc6a8f521df4eab165caf078c33fa.tar.gz Tango-8d2b13aaa70bc6a8f521df4eab165caf078c33fa.zip | |
DataStore Improvements.
Diffstat (limited to 'Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs b/Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs index e61385ab8..c76a3b6d9 100644 --- a/Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs +++ b/Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs @@ -40,21 +40,49 @@ namespace Tango.DataStore.Lite }); } + public T Get<T>(string key) + { + return (T)Convert.ChangeType(Get(key), typeof(T)); + } + + public T Get<T>(string key, T defaultValue) + { + return (T)Convert.ChangeType(Get(key, defaultValue), typeof(T)); + } + public object Get(string key) { + return Get(key, null); + } + + public object Get(string key, object defaultValue) + { + return GetItem(key, defaultValue).Value; + } + + public IDataStoreItem GetItem(string key) + { + return GetItem(key, null); + } + + public IDataStoreItem GetItem(string key, object defaultValue) + { var item = _collection.FindById(key); if (item == null) { - throw new KeyNotFoundException("The specified key was not found on the data store."); + if (defaultValue == null) + { + throw new KeyNotFoundException("The specified key was not found on the data store."); + } + else + { + Put(key, defaultValue); + return GetItem(key); + } } - return item.Value; - } - - public T Get<T>(string key) - { - return (T)Convert.ChangeType(Get(key), typeof(T)); + return item; } public List<IDataStoreItem> GetAll() @@ -77,11 +105,6 @@ namespace Tango.DataStore.Lite return _collection.Count(); } - public IDataStoreItem GetItem(string key) - { - return _collection.FindById(key); - } - public List<IDataStoreItem> GetUnsynchronized() { return _collection.Find(x => !x.IsSynchronized).ToList(); |
