-
Notifications
You must be signed in to change notification settings - Fork 6k
Add file based program tutorial #47886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a lot of feedback on this one 😸 I think it's good feedback but please feel free to push back on whatever you think doesn't make sense. Let me know when you want another review.
@@ -0,0 +1,246 @@ | |||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment:
There are a lot of mixed "file based" and "file-based" references here that you should fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I swept the other content I wrote for this feature as well. The correct product team term is "file-based app". I standardized on that everywhere.
|
||
> [!IMPORTANT] | ||
> | ||
> The version `2.0.0-beta6` was the latest version when this tutorial was last updated. If there's a newer version available, use the latest version to ensure you have the latest security packages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same note as the previous package tip here.
Define the delay option and messages argument. In command-line applications, options typically begin with `--` (double dash) and can accept arguments. The `--delay` option accepts an integer argument that specifies the delay in milliseconds. The `messagesArgument` defines how any remaining tokens after options are parsed as text. Each token becomes a separate string in the array, but text can be quoted to include multiple words in one token. For example, `"This is one message"` becomes a single token, while `This is four tokens` becomes four separate tokens. Add the following code to create the <xref:System.CommandLine.Option`1?displayProperty=nameWithType> and <xref:System.CommandLine.Argument`1?displayProperty=nameWithType> objects to represent the command line option and argument: | ||
|
||
:::code language="csharp" source="./snippets/file-based-programs/AsciiArt.cs" id="OptionArgument"::: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to fit the style of a procedure. DO THIS and then follow up with info about why and the code.. I feel like you want to do this but for some reason you didn't 😁
-
Define the delay option and messages argument. Add the following code to create the
CommandLine.Option
andCommandLine.Argument
objects to represent the command line option and argument::::code language="csharp" source="./snippets/file-based-programs/AsciiArt.cs" id="OptionArgument":::
In command-line applications, options typically begin with
--
(double dash) and can accept arguments. The--delay
option accepts an integer argument that specifies the delay in milliseconds. ThemessagesArgument
defines how any remaining tokens after options are parsed as text. Each token becomes a separate string in the array, but text can be quoted to include multiple words in one token. For example,"This is one message"
becomes a single token, whileThis is four tokens
becomes four separate tokens.
This is the input file | ||
for a file based program. | ||
It prints the messages | ||
from a file or the | ||
command line. | ||
There are options you | ||
can choose for ASCII | ||
art and colors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something fun like
Hello from
_ _ _
__| | ___ | |_ _ __ ___| |_
/ _` |/ _ \| __| '_ \ / _ \ __|
| (_| | (_) | |_| | | | __/ |_
\__,_|\___/ \__|_| |_|\___|\__|
This is the input file
for a file based program.
It prints the messages
from a file or the
command line.
There are options you
can choose for ASCII
art and colors.
:::code language="csharp" source="./snippets/file-based-programs/AsciiArt.cs"::: | ||
|
||
In this tutorial, you learned to build a file-based program, where you build the program in a single C# file. These programs don't use a project file, and can use the `#!` directive on unix systems. Learners can create these programs after trying our [online tutorials](../../tour-of-csharp/tutorials/hello-world.md) and before building larger project-based programs. File based programs are also a great platform for command line utilities. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the code is only around 65 lines of code (with the //snippet comments removed) you could add a section to the end with all the code as an example. If you want to do that you need to prep the file first. You can't just reference the entire file because it will contain the //snippet codes. Add a // <all>
and // </all>
snippet at the top and bottom of the file, respectively. Then reference the all
snippet in the ::: code reference. This erases all of the other //snippet comments in the output.
set the `+x` permission on the file-based program. Fix build warnings.
Use extracted code snippets instead of inline code.
Co-authored-by: Andy (Steve) De George <[email protected]>
0ce87e9
to
9b68cdf
Compare
Fix build error
Fixes #46926
Add a tutorial to build a file-based program. Include packages, and define custom types.
Internal previews