Table of Contents

Set default values

Use attribute defaults or property initializers to provide values when an argument or option is omitted.

Options

public sealed partial record ListParameters
{
    [Option("--status", DefaultValue = "open")]
    public string Status { get; set; } = "";
}
[Option("--count", DefaultValue = 10)]
public int Count { get; set; }

Optional arguments

public sealed partial record CopyParameters
{
    [Argument(0)]
    public required string Source { get; init; }

    [OptionalArgument(1, DefaultValue = "output.txt")]
    public string Destination { get; set; } = "";
}

Variadic arguments

[VariadicArgument(1, DefaultValue = new[] { "all" })]
public string[] Values { get; set; } = [];

Property initializers

A property initializer is used when no command-line value or attribute default is supplied:

[Option("--data")]
public string DataFile { get; set; } = "tasks.json";

Priority

When a parameter is omitted, the order is:

  1. Attribute DefaultValue.
  2. Property initializer.

An explicitly supplied command-line value always overrides both.