Interface IConfigurationSerializer
Namespace: Void.Proxy.Api.Configurations.Serializer
Assembly: Void.Proxy.Api.dll
public interface IConfigurationSerializerMethods
Deserialize<TConfiguration>(string)
Deserializes configuration text into an instance of TConfiguration.
TConfiguration Deserialize<TConfiguration>(string source) where TConfiguration : notnullParameters
source string
The serialized configuration text to parse and map; this value must not be null.
Returns
TConfiguration
A configuration instance cast to TConfiguration.
Type Parameters
TConfiguration
The expected configuration type.
Examples
var value = serializer.Deserialize<NetworkConfiguration>(sourceText);
Remarks
This member is a typed wrapper around TConfiguration) as the target type.
The built-in serializer implementation parses TOML and maps it with configured options, then
validates that the resulting object can be cast to TConfiguration.
Exceptions
Thrown when source cannot be parsed, when it cannot be mapped to TConfiguration, or when the mapped result is not assignable to TConfiguration.
See Also
IConfigurationSerializer.Deserialize(string, Type)
Deserialize(string, Type)
Deserializes configuration text into an instance of a runtime-specified configuration type.
object Deserialize(string source, Type configurationType)Parameters
source string
The serialized configuration text to parse and map; this value must not be null.
configurationType Type
The target configuration
Returns
The deserialized configuration object typed as
Examples
var value = serializer.Deserialize(sourceText, typeof(NetworkConfiguration));
Remarks
The built-in serializer implementation first parses source as TOML, then maps
the parsed document to configurationType using serializer options.
This overload performs no compile-time type checks, so callers are responsible for casting the returned value to the expected runtime type.
Exceptions
Thrown when parsing fails or when the serialized content cannot be converted to configurationType.
See Also
IConfigurationSerializer.Deserialize<TConfiguration>(string), Type
Serialize<TConfiguration>()
Serializes a default-value instance of TConfiguration to configuration text.
string Serialize<TConfiguration>() where TConfiguration : notnullReturns
A TConfiguration instance populated with its default property values.
Type Parameters
TConfiguration
The configuration type whose default representation is serialized. Must be a non-nullable reference or value type.
Examples
// Produce a template TOML configuration file with all default values.
string template = serializer.Serialize<NetworkConfiguration>();
await File.WriteAllTextAsync("network.toml", template);
Remarks
This overload is a convenience wrapper that calls
TConfiguration).
Because no existing instance is provided, the underlying serializer constructs a fresh
TConfiguration instance using its default constructor and fills
all properties with their default values before serializing. The result is therefore
useful for generating template or scaffold configuration files.
Exceptions
Thrown when the serializer cannot construct a default TConfiguration
instance or cannot convert it to the target configuration format.
See Also
IConfigurationSerializer.Serialize<TConfiguration>(TConfiguration?), IConfigurationSerializer.Serialize(object?, Type)
Serialize(object)
string Serialize(object configuration)Parameters
configuration object
Returns
Serialize<TConfiguration>(TConfiguration?)
string Serialize<TConfiguration>(TConfiguration? configuration) where TConfiguration : notnullParameters
configuration TConfiguration?
Returns
Type Parameters
TConfiguration
Serialize(object?, Type)
Serializes the given configuration object — or a default instance of configurationType when configuration is null — to configuration text.
string Serialize(object? configuration, Type configurationType)Parameters
configuration object?
The configuration object to serialize, or null to serialize a freshly
constructed default instance of configurationType.
configurationType Type
The configuration is non-null, this must match or be a base type of the
runtime type of configuration.
Returns
A
Examples
// Serialize an existing configuration instance with an explicit type.
string toml = serializer.Serialize(myConfig, typeof(NetworkConfiguration));
// Serialize a default instance by passing null for the configuration argument.
string defaults = serializer.Serialize(null, typeof(NetworkConfiguration));
Remarks
This is the canonical serialization overload to which all other Serialize overloads
ultimately delegate. It performs the following steps:
-
If
configurationis null, a new instance ofconfigurationTypeis created with all properties set to their default values. -
The object is mapped to a
TomlDocumenttogether with any inline or preceding comments declared via. -
The serialized TOML text is returned via
TomlDocument.SerializedValue.
Exceptions
Thrown when the underlying TOML library raises a TomlException during object mapping
or serialization. The exception message includes the original TOML error details.
See Also
IConfigurationSerializer.Serialize<TConfiguration>(), IConfigurationSerializer.Serialize<TConfiguration>(TConfiguration?), IConfigurationSerializer.Deserialize(string, Type)