diff options
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(); |
