Skip to main content

Advanced configuration

You can use complex data types for configuration in YAML instancing. Make sure you are not using immutable data types like strings or read-only collections without making them nullable. For collections we recommend using IList<T> that are instanced with List<T> if you do not want to be nullable.

Advanced configuration

Examples of configurations:

YAML type.NET type
AString: hello world
AnInt: 10
ABool: true

string? AString { get; set; }
int? AnInt {get;set;}
bool? ABool { get; set; }
- Hello
- World
IList&ltstring&gt SimpleList { get; set; }
Sequences can also be IEnumerable&lttype&gt, but must then be nullable

Example of complex data types support

This example shows an example of how to use complex configuration options.

ComplexConfig: # This should have the same name as class
AString: hello world
AnInt: 10
ABool: true
- this
- is
- cool!
- name: tv
- name: command1
data: some code
- name: command2
data: some code2";
// The app using the config
public class ComplexConfigApp

public ComplexConfigApp(IAppConfig<ComplexConfig> config)
ComplexConfig complexConfig = config.Value;

// Use config
foreach(var device in complexConfig.Devices)
// Do something useful or fun

public class ComplexConfig
public string? AString { get; set; }
public int? AnInt { get; set; }
public bool? ABool { get; set; }
public IList<string> AStringList { get; set; }
public IEnumerable<Device>? Devices { get; set; }

public class Device
public string? name { get; set; }
public IEnumerable<Command>? commands { get; set; }
public class Command
public string? name { get; set; }
public string? data { get; set; }



My config properties are all null.


Ensure your YAML file is being copied to the output folder.


Ensure the following is in your .csproj file to do this automatically for all YAML files:

<None Include="apps\**\*.yaml">

Alternatively, set Copy to Output Directory to Copy Always.