Skip to content

Commit ddaddfc

Browse files
committed
docs: Update samples to show default values using attribute API
1 parent 1524f56 commit ddaddfc

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,16 @@ public class Program
5555
=> CommandLineApplication.Execute<Program>(args);
5656

5757
[Option(Description = "The subject")]
58-
public string Subject { get; }
58+
public string Subject { get; } = "world";
5959

6060
[Option(ShortName = "n")]
61-
public int Count { get; }
61+
public int Count { get; } = 1;
6262

6363
private void OnExecute()
6464
{
65-
var subject = Subject ?? "world";
6665
for (var i = 0; i < Count; i++)
6766
{
68-
Console.WriteLine($"Hello {subject}!");
67+
Console.WriteLine($"Hello {Subject}!");
6968
}
7069
}
7170
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using McMaster.Extensions.CommandLineUtils;
3+
4+
public class Program
5+
{
6+
public static int Main(string[] args)
7+
=> CommandLineApplication.Execute<Program>(args);
8+
9+
[Option(Description = "The subject")]
10+
public string Subject { get; } = "world";
11+
12+
[Option(ShortName = "n")]
13+
public int Count { get; } = 1;
14+
15+
private void OnExecute()
16+
{
17+
for (var i = 0; i < Count; i++)
18+
{
19+
Console.WriteLine($"Hello {Subject}!");
20+
}
21+
}
22+
}

docs/samples/samples.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuilderApi", "generic-host\
6363
EndProject
6464
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "helloworld\HelloWorld.csproj", "{D444D44D-76BB-4FDB-9C06-1D8D30729F4A}"
6565
EndProject
66+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldAttributes", "helloworld-attributes\HelloWorldAttributes.csproj", "{81F83C18-B60C-4A3F-8896-4B280A8F06D6}"
67+
EndProject
6668
Global
6769
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6870
Debug|Any CPU = Debug|Any CPU
@@ -361,6 +363,18 @@ Global
361363
{D444D44D-76BB-4FDB-9C06-1D8D30729F4A}.Release|x64.Build.0 = Release|Any CPU
362364
{D444D44D-76BB-4FDB-9C06-1D8D30729F4A}.Release|x86.ActiveCfg = Release|Any CPU
363365
{D444D44D-76BB-4FDB-9C06-1D8D30729F4A}.Release|x86.Build.0 = Release|Any CPU
366+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
367+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
368+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Debug|x64.ActiveCfg = Debug|Any CPU
369+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Debug|x64.Build.0 = Debug|Any CPU
370+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Debug|x86.ActiveCfg = Debug|Any CPU
371+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Debug|x86.Build.0 = Debug|Any CPU
372+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
373+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|Any CPU.Build.0 = Release|Any CPU
374+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|x64.ActiveCfg = Release|Any CPU
375+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|x64.Build.0 = Release|Any CPU
376+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|x86.ActiveCfg = Release|Any CPU
377+
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|x86.Build.0 = Release|Any CPU
364378
EndGlobalSection
365379
GlobalSection(SolutionProperties) = preSolution
366380
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)