Class FileDataStore
File data store that implements Google.Apis.Util.Store.IDataStore. This store creates a different file for each combination of type and key. This file data store stores a JSON format of the specified object.
Inheritance
Implements
Inherited Members
Namespace: Google.Apis.Util.Store
Assembly: Google.Apis.dll
Syntax
public class FileDataStore : IDataStore
Constructors
FileDataStore(String, Boolean)
Constructs a new file data store. If fullPath
is false
the path will be used as relative to
Environment.SpecialFolder.ApplicationData"
on Windows, or $HOME
on Linux and MacOS,
otherwise the input folder will be treated as absolute.
The folder is created if it doesn't exist yet.
Declaration
public FileDataStore(string folder, bool fullPath = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | folder | Folder path. |
System.Boolean | fullPath | Defines whether the folder parameter is absolute or relative to
|
Properties
FolderPath
Gets the full folder path.
Declaration
public string FolderPath { get; }
Property Value
Type | Description |
---|---|
System.String |
Methods
ClearAsync()
Clears all values in the data store. This method deletes all files in FolderPath.
Declaration
public Task ClearAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
DeleteAsync<T>(String)
Deletes the given key. It deletes the GenerateStoredKey(String, Type) named file in FolderPath.
Declaration
public Task DeleteAsync<T>(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to delete from the data store. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Type Parameters
Name | Description |
---|---|
T |
GenerateStoredKey(String, Type)
Creates a unique stored key based on the key and the class type.
Declaration
public static string GenerateStoredKey(string key, Type t)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The object key. |
System.Type | t | The type to store or retrieve. |
Returns
Type | Description |
---|---|
System.String |
GetAsync<T>(String)
Returns the stored value for the given key or null
if the matching file (GenerateStoredKey(String, Type)
in FolderPath doesn't exist.
Declaration
public Task<T> GetAsync<T>(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to retrieve from the data store. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<T> | The stored object. |
Type Parameters
Name | Description |
---|---|
T | The type to retrieve. |
StoreAsync<T>(String, T)
Stores the given value for the given key. It creates a new file (named GenerateStoredKey(String, Type)) in FolderPath.
Declaration
public Task StoreAsync<T>(string key, T value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key. |
T | value | The value to store in the data store. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Type Parameters
Name | Description |
---|---|
T | The type to store in the data store. |