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.
Implements
Inherited Members
Namespace: Google.Apis.Util.Store
Assembly: Google.Apis.dll
Syntax
public class FileDataStore : IDataStore
Constructors
FileDataStore(string, bool)
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 |
---|---|---|
string | folder | Folder path. |
bool | 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 |
---|---|
string |
Methods
ClearAsync()
Clears all values in the data store. This method deletes all files in FolderPath.
Declaration
public Task ClearAsync()
Returns
Type | Description |
---|---|
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 |
---|---|---|
string | key | The key to delete from the data store. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
string | key | The object key. |
Type | t | The type to store or retrieve. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
string | key | The key to retrieve from the data store. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
string | key | The key. |
T | value | The value to store in the data store. |
Returns
Type | Description |
---|---|
Task |
Type Parameters
Name | Description |
---|---|
T | The type to store in the data store. |