Compare commits

..

5 Commits
v0.1 ... master

Author SHA1 Message Date
0e7a40a639 Merge pull request 'dev_0.2' (#4) from dev_0.2 into master
Reviewed-on: #4
2024-08-12 12:53:20 +09:00
d9e3e7bf3b #3 の対応 2024-08-12 12:46:55 +09:00
c8c152ae68 #2 の対応 2024-08-12 12:30:07 +09:00
39561ef837 fix: readme 2024-08-12 12:10:13 +09:00
883236e581 Merge pull request 'fix: readme' (#1) from dev_0.2 into master
Reviewed-on: #1
2024-08-12 12:09:54 +09:00
4 changed files with 28 additions and 1 deletions

View File

@ -6,5 +6,9 @@ public interface IStore<T> : IDisposable
public bool Add(T item);
public bool Has(T item);
public bool Remove(T item);
public IEnumerable<T> GetValues();
}

View File

@ -29,6 +29,9 @@ public class LocalStore<T> : IStore<T>
using (FileStream fs = new FileStream(this.filePath, FileMode.OpenOrCreate))
using (StreamWriter writer = new StreamWriter(fs, DefaultEncoding))
{
fs.Seek(0, SeekOrigin.Begin);
fs.SetLength(0);
foreach (T item in this.items)
{
string json = JsonSerializer.Serialize<T>(item);
@ -53,6 +56,16 @@ public class LocalStore<T> : IStore<T>
return true;
}
public bool Has(T item)
{
return this.items.Contains(item);
}
public bool Remove(T item)
{
return this.items.Remove(item);
}
public IEnumerable<T> GetValues()
{
return this.items.ToList();

View File

@ -26,6 +26,16 @@ public class JsonDB<T> : IDisposable
return this.store.Add(item);
}
public bool Has(T item)
{
return this.store.Has(item);
}
public bool Remove(T item)
{
return this.store.Remove(item);
}
public IEnumerable<T> GetValues()
{
return this.store.GetValues();

View File

@ -20,7 +20,7 @@ bool result = jsonDB.Add(new T());
IEnumerable<T> allItems = jsonDB.GetValues();
// DBから特定のアイテムを取得します。
IEnumerable<T> filteredItems = jsonDB.GetValues((T) => true):
IEnumerable<T> filteredItems = jsonDB.GetValues((T) => true);
// ファイルに書き込む
jsonDB.Commit();