aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-10-23 03:13:09 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-10-23 03:13:09 +0300
commit8d2b13aaa70bc6a8f521df4eab165caf078c33fa (patch)
tree325567b00d55fa751da7492be067e7878b132e28 /Software/Visual_Studio/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs
parenta79900d579ae9f624b35aa933784e4e0f0c65d03 (diff)
downloadTango-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.cs47
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();