AutoSpectre.SourceGeneration
0.4.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package AutoSpectre.SourceGeneration --version 0.4.0
NuGet\Install-Package AutoSpectre.SourceGeneration -Version 0.4.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutoSpectre.SourceGeneration" Version="0.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutoSpectre.SourceGeneration --version 0.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AutoSpectre.SourceGeneration, 0.4.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AutoSpectre.SourceGeneration as a Cake Addin #addin nuget:?package=AutoSpectre.SourceGeneration&version=0.4.0 // Install AutoSpectre.SourceGeneration as a Cake Tool #tool nuget:?package=AutoSpectre.SourceGeneration&version=0.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AutoSpectre Source Generation
This allows you to decorate a class with the AutoSpectreForm
attribute and properties on that class with AskAttribute
and behind the scenes a Form will be generated to request input using Spectre.Console
Example
Code
[AutoSpectreForm]
public class Someclass
{
[Ask(AskType = AskType.Normal, Title = "Add item")]
public int[] IntItems { get; set; } = Array.Empty<int>();
[Ask(Title = "Enter first name")]
public string? FirstName { get; set; }
[Ask]
public bool LeftHanded { get; set; }
[Ask(Title = "Choose your [red]value[/]")]
public SomeEnum Other { get; set; }
[Ask]
public Name Owner { get; set; } = new Name();
[Ask]
public IReadOnlyList<Name> Investors { get; set; } = new List<Name>();
[Ask(AskType = AskType.Selection, SelectionSource = nameof(Items))]
public string Item { get; set; } = string.Empty;
public List<string> Items { get; } = new List<string>() { "Alpha", "Bravo", "Charlie" };
}
Output
public interface ISomeclassSpectreFactory
{
Someclass Get(Someclass destination = null);
}
public class SomeclassSpectreFactory : ISomeclassSpectreFactory
{
public Someclass Get(Someclass destination = null)
{
INameSpectreFactory NameSpectreFactory = new NameSpectreFactory();
destination ??= new Test.Someclass();
// Prompt for values for destination.IntItems
{
List<int> items = new List<int>();
bool continuePrompting = true;
do
{
var item = AnsiConsole.Prompt(new TextPrompt<int>("Add item"));
items.Add(item);
continuePrompting = AnsiConsole.Confirm("Add more items?");
}
while (continuePrompting);
int[] result = items.ToArray();
destination.IntItems = result;
}
destination.FirstName = AnsiConsole.Prompt(new TextPrompt<string?>("Enter first name").AllowEmpty());
destination.LeftHanded = AnsiConsole.Confirm("Enter [green]LeftHanded[/]");
destination.Other = AnsiConsole.Prompt(new SelectionPrompt<SomeEnum>().Title("Choose your [red]value[/]").PageSize(10).AddChoices(Enum.GetValues<SomeEnum>()));
{
AnsiConsole.MarkupLine("Enter [green]Owner[/]");
var item = NameSpectreFactory.Get();
destination.Owner = item;
}
// Prompt for values for destination.Investors
{
List<Name> items = new List<Name>();
bool continuePrompting = true;
do
{
{
AnsiConsole.MarkupLine("Enter [green]Investors[/]");
var newItem = NameSpectreFactory.Get();
items.Add(newItem);
}
continuePrompting = AnsiConsole.Confirm("Add more items?");
}
while (continuePrompting);
System.Collections.Generic.IReadOnlyList<Test.Name> result = items;
destination.Investors = result;
}
destination.Item = AnsiConsole.Prompt(new SelectionPrompt<string>().Title("Enter [green]Item[/]").PageSize(10).AddChoices(destination.Items.ToArray()));
return destination;
}
}
Credits
There are no supported framework assets in this package.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- AutoSpectre (>= 0.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.4.0)
- Spectre.Console (>= 0.47.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.9.0 | 135 | 7/2/2024 |
0.9.0-preview-0.6 | 60 | 7/1/2024 |
0.8.2 | 104 | 6/25/2024 |
0.8.2-preview-01 | 88 | 6/23/2024 |
0.8.1 | 158 | 2/5/2024 |
0.8.0 | 222 | 11/30/2023 |
0.8.0-preview.0.1 | 109 | 11/4/2023 |
0.7.0 | 303 | 10/3/2023 |
0.7.0-preview.0.8 | 91 | 10/2/2023 |
0.7.0-preview.0.7 | 73 | 10/2/2023 |
0.7.0-preview.0.6 | 86 | 10/1/2023 |
0.7.0-preview.0.5 | 81 | 9/26/2023 |
0.7.0-preview.0.4.2 | 80 | 9/20/2023 |
0.7.0-preview.0.3 | 63 | 9/18/2023 |
0.7.0-preview.0.2 | 82 | 9/15/2023 |
0.7.0-preview.0.1 | 92 | 9/14/2023 |
0.6.0 | 340 | 9/12/2023 |
0.6.0-preview.0.4 | 82 | 9/10/2023 |
0.6.0-preview.0.1 | 78 | 9/3/2023 |
0.5.3 | 317 | 8/28/2023 |
0.5.2 | 321 | 8/27/2023 |
0.5.1 | 324 | 8/25/2023 |
0.5.0 | 334 | 8/23/2023 |
0.4.0 | 352 | 8/15/2023 |
0.3.8 | 353 | 8/6/2023 |
0.3.7.2 | 216 | 7/29/2023 |
0.3.6.1 | 213 | 7/25/2023 |
0.3.5 | 176 | 7/24/2023 |
0.3.4 | 198 | 7/23/2023 |
0.3.3 | 185 | 7/23/2023 |
0.3.2 | 352 | 1/22/2023 |
0.3.1 | 358 | 1/16/2023 |
0.3.0 | 367 | 1/6/2023 |
0.2.0.2 | 356 | 12/14/2022 |
0.2.0.1 | 329 | 12/14/2022 |
0.1.6 | 391 | 12/2/2022 |
0.1.5 | 370 | 11/30/2022 |
Rewrite that adds TextPrompt and SelectionPrompt attributes instead of the AskAttribute. More properties
added to these two attributes