Description
The GetMetaOrDefault
method retrieves a metadata value associated with the specified key from the project configuration. If the key does not exist, it returns a default value provided by the caller. This method is useful for accessing custom metadata stored in the project configuration without having to check for the existence of the key manually.
Usage
To use the GetMetaOrDefault
method, call it on an instance of ProjectConfig
, passing the key name as a string and the default value of type T
that you want to return if the key is not found.
Parameters:
keyname
(System.String): The name of the metadata key to retrieve.
defaultValue
(T): The default value to return if the key is not found.
Returns: The value associated with the specified key if it exists; otherwise, the defaultValue
.
Example
// Example usage of GetMetaOrDefault
var projectConfig = new ProjectConfig();
// Assume "author" is a metadata key that might not exist
string author = projectConfig.GetMetaOrDefault("author", "Unknown Author");
// If "author" key exists, it will return its value, otherwise "Unknown Author" will be returned
Console.WriteLine($"Author: {author}");