-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v12.0' into BMichaelis/ChangePreviewTo12.0
- Loading branch information
Showing
646 changed files
with
2,657 additions
and
2,715 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ jobs: | |
contents: write | ||
|
||
steps: | ||
- uses: fastify/[email protected].0 | ||
- uses: fastify/[email protected].1 | ||
with: | ||
use-github-auto-merge: true | ||
|
||
|
@@ -29,7 +29,7 @@ jobs: | |
matrix: | ||
os: [ubuntu-latest, windows-latest, macOS-latest] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- name: Setup dotnet SDK | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Sync branches | ||
on: | ||
push: | ||
branches: [ 'v12.0', 'v13.0' ] | ||
|
||
jobs: | ||
sync_branches: | ||
name: Sync Branches | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Keep branches in sync | ||
uses: jojomatik/[email protected] | ||
with: | ||
source: "v12.0" | ||
target: "v13.0" | ||
strategy: "merge" | ||
resolve_conflicts: "false" | ||
git_committer_name: 'BenjaminMichaelisBot' | ||
git_committer_email: '[email protected]' | ||
# The access token to push to the repository | ||
# Optional | ||
# Default: github.token | ||
github_token: ${{ secrets.GIT_PUSHTOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" /> | ||
<PackageVersion Include="IntelliTect.Multitool" Version="1.4.0" /> | ||
<PackageVersion Include="IntelliTect.TestTools.Console" Version="1.0.0" /> | ||
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.7.0" /> | ||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.7.0" /> | ||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.MSTest" Version="1.1.1" /> | ||
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" /> | ||
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" /> | ||
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" /> | ||
<PackageVersion Include="System.Linq.Async" Version="6.0.1" /> | ||
<PackageVersion Include="System.Reflection" Version="4.3.0" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,15 @@ | ||
# Essential C# 8.0 Errata Document | ||
# Essential C# 12.0 Errata Document | ||
|
||
## Essential C# 12.0 | ||
|
||
## Essential C# 8.0 | ||
by Mark Michaelis | ||
ISBN-13: 978-0-13-597226-7 | ||
IISBN-10: 0-13-597226-4 | ||
Copyright © 2021 Pearson Education, Inc. | ||
First printing, October 2020 | ||
ISBN-13: | ||
IISBN-10: | ||
Copyright © 2023 Pearson Education, Inc. | ||
First printing, November 2023 | ||
|
||
The following corrections will be made in the second printing. (To determine which printing you have, turn to page IV of your book. The last line on that page contains the printing information.) | ||
|
||
Found by | Chapter | Page | Correction | ||
Found by | Chapter | Page | Correction | ||
------------------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
Salim Gangji | 1 | 12 | First paragraph: For a single executable, append <s>`/p:PublishSingleFile=true`</s> `-p:PublishSingleFile=true` to the command | ||
Pieter Le Roux | 1 | 31 | Last Line: Table 1.2 shows four different C# comment types. The program in <s>Listing 1.18</s> Listing 1.19 includes two of these. | ||
Benjamin Michaelis | 1 | 31 | Last Line: Table 1.2 shows four different C# comment types. The program in Listing 1.19 includes <s>two</s>three of these. | ||
Salim Gangji | 2 | 51 | Output 2.3: <s>1.61803398874985</s> 1.618033988749895 | ||
Alden Bansemer | 2 | 55 | Listing 2.9: <s>`result == number`</s> `{result} == {number}`. Output 2.7: <s>`result == number`</s> `1.61803398874989 == 1.61803398874989`. | ||
Alden Bansemer | 3 | 89 | Listing 3.4: Changed <s>`class 3.2->3.Uppercase`</s> to match source `class Uppercase`. | ||
Alden Bansemer | 3 | 113 | Output 3.2: `TypeScript` replaced with `Visual Basic` as last element in sorted array and first element in the reversed, sorted array. | ||
Alden Bansemer | 3 | 114 | Output 3.3: Added missing second line of output: `3`. | ||
Alden Bansemer | 4 | 129 | Listing 4.7: Removed Trace.Assert to match codebase. Removed example #4, float converted to double now matches the double. | ||
Alden Bansemer | 4 | 130 | Output 4.6: Updated results of Listing 4.7 to remove <s>`4.20000006258488 != 4.20000028610229`</s>. | ||
Pieter Le Roux | 5 | 215 | Output 5.4: ERROR: You must specify the URL <s>to be downloaded</s> and the file name **Usage:** Downloader.exe <URL> <TargetFileName> | ||
Pieter Le Roux | 6 | 285 | Last Line in second paragraph: "DO use nameof for the paramName argument passed into exceptions like Argument<s>Null</s>Exception and ArgumentNullException that take such a parameter. For more information, see Chapter 18." | ||
Pieter Le Roux | 7 | 359 | return <s>@</s>$"FirstName: { FirstName + NewLine }" + $"LastName: { LastName + NewLine }"+ $"Address: { Address + NewLine }"; | ||
Benjamin Michaelis | 7 | 359 | make the s in 'string bold' "set { string[] names = value.Split(' ');" | ||
Pieter Le Roux | 10 | 452 | Last paragraph: "so <s>overloading</s> overriding the method" "Consider <s>overloading</s>overriding the ToString() method " | ||
Pieter Le Roux | 10 | 458 | Output 10.2: "serialNumber1 reference equals serialNumber2 **serialNumber1 equals serialNumber2** serialNumber1 equals serialNumber3" | ||
Pieter Le Roux | 10 | 460 | Note: "The implementation of object.Equals(), the default implementation on all objects before <s>overloading</s>overriding, relies on ReferenceEquals() alone." | ||
Pieter Le Roux | 10 | 464 | "To correct this flaw, it is important to <s>overload</s>override the equals (==) and not equals (!=) operators as well | ||
Pieter Le Roux | 12 | 581 | Listing 12.47: .class <s>private</s>public auto ansi beforefieldinit Stack'1<([<s>mscorlib</s>System.Runtime]System.IComparable)** **T> extends [<s>mscorlib</s>System.Runtime]System.Object { ... } | ||
Benjamin Michaelis | 12 | 582 | Listing 12.48: .class public auto ansi beforefieldinit <s>'</s>Stack'1<s>'</s><([<s>mscorlib</s>System.Runtime]System.IComparable) T> extends [<s>mscorlib</s>System.Runtime]System.Object { .field private !<s>0</s>**T**[ ] _Items ... } | ||
Pieter Le Roux | 12 | 542 | "you can see that the type parameter will be used for the <s>internal Items</s>InternalItems array, the type for the parameter to the" | ||
Pieter Le Roux | 12 | 547 | "constructor that takes the initial values for both <s>First and Second</s>first and second and assigns them to First and Second." | ||
Pieter Le Roux | 12 | 551 | "// Use System.ValueTup**l**e<string,Contact> prior to C# 7.0 " | ||
Pieter Le Roux | 12 | 579 | "Consider the **I**PairInitializer<in T> interface in Listing 12.45." | ||
Pieter Le Roux | 13 | 602 | "the compiler can <s>see</s>infer that the lambda" | ||
Pieter Le Roux | 14 | 639 | Output 14.2: "<s>Enter temperature: 45 Heater: On Error in the application Cooler: Off</s> Enter temperature: 45 Heater: On Cooler: Off There were exceptions thrown by OnTemperatureChange Event subscribers. (Operation is not valid due to the current state of the object.)" | ||
Pieter Le Roux | 15 | 686 | tabs in Output 15.9 doesn't reflect Listing 15.21. Fixed by updating source code | ||
Pieter Le Roux | 15 | 700 | // ERROR: Cannot implicitly convert type // 'AnonymousType<s>#3</s>#1' to 'AnonymousType<s>#2</s>#3' | ||
Pieter Le Roux | 16 | 706 | Reorder keywords to alphabetical order in Listing 16.1, and add missing keywords | ||
Pieter Le Roux | 16 | 707 | "private static void Show<s>Contextual</s>Keywords1()" | ||
Pieter Le Roux | 16 | 712 | Output 16.3 is missing "when" | ||
Pieter Le Roux | 16 | 715 | "File.GetLastWriteTime(file**Name**)" | ||
Pieter Le Roux | 16 | 719 | Add "when" to Output 16.6 ("when*" was missing from source code) | ||
Pieter Le Roux | 16 | 721 | Add "when" to Output 16.7 ("when*" was missing from source code) | ||
Pieter Le Roux | 16 | 725 | in Listing 16.16 and Listing 16.17, add "!" prior to "word. Contains('*')" to match Listing 16.01 | ||
Pieter Le Roux | 17 | 733 | Saw List[6] could throw error. Changed to "{ List[<s>6</s>^1] } | ||
Pieter Le Roux | 17 | 760 | "as you did in both CSharp<s>PrimitiveTypes</s>BuiltInTypes" | ||
Pieter Le Roux | 18 | 776 | errorMessage listed twice in listing 18.3 | ||
Pieter Le Roux | 18 | 807 | "let's reexamine Listing <s>18.28</s>18.27. Notice the call to retrieve the "FirstName" element:" | ||
Pieter Le Roux | 19 | 824 | "The worker thread will write <s>periods</s>plus signs to the console | ||
Pieter Le Roux | 19 | 825 | lambda expression prints out <s>dashes</s>hyphens to the console repeatedly. | ||
Pieter Le Roux | 19 | 840 | "<s>(c)</s>(3)" | ||
Benjamin Michaelis | 4 | 180-181 | Replace `EventArgs` with `PropertyChangedEventArgs(nameof(Property))` in Leveraging the Null-Conditional Operator with Delegates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,88 @@ | ||
# EssentialCSharp | ||
|
||
[![Build and Test](https://github.com/IntelliTect/EssentialCSharp/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/IntelliTect/EssentialCSharp/actions/workflows/build-and-test.yml) | ||
|
||
This project contains the source code for the book **Essential C#** by Mark Michaelis (Addison-Wesley). | ||
|
||
## Sample Code Guide | ||
## Checkout the online resource that walks through all code samples in this repository at [EssentialCSharp.com](https://essentialcsharp.com) | ||
|
||
Ensure one of the following frameworks is installed at the latest version. | ||
## Requirements | ||
|
||
- [.NET](https://www.microsoft.com/net/core) (All) - This project is currently tested against .NET 7.0 and .NET 6.0. | ||
- [Visual Studio](https://www.visualstudio.com) contains .NET Core to get up and running. Not to mention, it's a great IDE that makes it easy to get started. | ||
- [.NET](https://www.microsoft.com/net/core) - This project is currently tested against .NET 8.0, 7.0, and 6.0. | ||
- [Visual Studio](https://visualstudio.microsoft.com/downloads/) - Already contains .NET Core to get up and running. Not to mention, it's a great IDE that makes it easy to get started. | ||
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) - While not required, a good tool to get used to, and easy way to download this code repository quickly. [GitKraken](https://www.gitkraken.com/invite/bX2Nqsqr) is a great GUI for using Git if you prefer not using the command line. | ||
|
||
### Download the Code | ||
## Download the Code | ||
|
||
#### Local Copy | ||
### Local Copy | ||
|
||
Open a console and change the working directory to the desired project location. | ||
|
||
``` | ||
```bash | ||
git clone https://github.com/IntelliTect/EssentialCSharp.git | ||
cd ./EssentialCSharp/ | ||
``` | ||
|
||
The source code is the most recently published edition of the book and this is the default branch following the clone command. However, you can switch to a different branch, v12.0 for example, with the command: | ||
|
||
``` | ||
```bash | ||
git checkout v12.0 | ||
``` | ||
|
||
### Build | ||
## Running the Code | ||
|
||
**EssentialCSharp.sln** is the project's main solution, open this with Visual Studio and _Build All_. | ||
### Visual Studio | ||
|
||
For those using the command line, build all the projects from the /EssentialCSharp/ directory with these commands: | ||
1. **EssentialCSharp.sln** is the project's main solution, open this with Visual Studio. | ||
2. After opening the solution file, use the Build->Build Solution menu to compile the code with Visual Studio. | ||
- NOTE: Before you can execute the source code, you need to select which project to execute by selecting the associated chapter’s project as the startup project. For example, to execute the samples in Chapter 1, you would right-click on the Chapter01 project and choose Set as Startup Project. Failure to choose the correct chapter will result in an exception with the message “Error, could not run the Listing…” when you specify the listing number at execution time. | ||
3. To run the code, press F5 or select Debug->Start Debugging from the menu. | ||
4. Once running, the program will prompt for the listing (e.g., 18.33) that you wish to execute. | ||
- NOTE: As mentioned earlier, you can enter only listings from the project that was set to start up. | ||
|
||
``` | ||
dotnet restore EssentialCSharp.sln | ||
dotnet build EssentialCSharp.sln | ||
``` | ||
### Dotnet CLI | ||
|
||
### Run | ||
1. Navigate to the root directory of the EssentialCSharp from your local terminal (the root directory is the one that contains the `EssentialCSharp.sln` file). | ||
2. From that root directory, run the following commands to restore and build all the projects: | ||
|
||
Navigate to an individual project in the /EssentialCSharp/src/(project)/ directory and run the code. The example below is for Chapter01 with the user entering _1.1_ to execute the listing number. | ||
```C# | ||
dotnet restore | ||
dotnet build | ||
``` | ||
|
||
To run a listing you must run the the project that contains it. For example, to run Listing 1.1 you must navigate to Chapter01 in the | ||
_Solution Explorer_ and set Chapter01 as the startup project. In Rider this can be done by locating the desired project in the _Explorer_ tab, right clicking on the project and clicking _run_. | ||
3. To run the code, first navigate to the project directory of the chapter you wish to execute. For example, to execute the samples in Chapter 1, you would navigate to the Chapter01 directory (ex: `cd src/Chapter01`). | ||
4. Then use the `dotnet run` command to begin the program and follow the prompts for which listing to execute. | ||
- NOTE: You can enter only listings from the project that is set to run (Chapter01 in this sample). | ||
5. Instead of navigating to the chapter directory of the project you want to run, you can use the `dotnet run -p <projectfile>` command where project file is the path to the project file you are trying to execute (e.g., `dotnet run -p .\src\Chapter01\Chapter01.csproj`). Once executing, the program will prompt for which listing to execute and then proceed with that listing. | ||
|
||
``` | ||
$ cd ./src/Chapter01/ | ||
$ dotnet run | ||
Enter the listing number to execute (e.g. For Listing 1.1 enter "1.1"): 1.1 | ||
Documentation for .NET CLI tools can be found here: | ||
|
||
____________________________ | ||
<https://docs.microsoft.com/en-us/dotnet/core/tools/> | ||
|
||
Hello. My name is Inigo Montoya. | ||
## Testing | ||
|
||
____________________________ | ||
End of Listing 01_01 | ||
Press any key to exit. | ||
$ | ||
``` | ||
Many of the listings have corresponding unit tests. | ||
|
||
Documentation for .NET CLI tools can be found here: | ||
In Visual Studio, to execute a test, open the test project and navigate to the test corresponding to the listing you wish to execute. From there, right-click on the test method and choose either Run Tests (Ctrl+R, T) or Debug Tests (Ctrl+R, Ctrl+T). Alternatively, open your Test Explorer window and run some or all of the tests from there ([More Information](https://learn.microsoft.com/visualstudio/test/run-unit-tests-with-test-explorer)) | ||
<https://docs.microsoft.com/en-us/dotnet/core/tools/> | ||
In dotnet test, to run all the tests across all projects, run `dotnet test` on the command prompt in the root EssentialCSharp directory (the root directory is the one that contains the `EssentialCSharp.sln` file). To run the tests for a single project, use the dotnet test command from the project tests directory of the test you are looking execute. | ||
|
||
## Testing | ||
## Reading the Source Code | ||
|
||
In the source code there are some things that may look different than when you look at the source code in the book. This is because even though the examples in the book come directly from this repository, not all of the code is shown in the book like it is here. | ||
|
||
Some helpful things to note: | ||
|
||
When you see matching `#region INCLUDE` and `#endregion INCLUDE` tags in a listing, between these two tags are where the source code that is able to be seen in this book lies. | ||
|
||
When there are matching `#region EXCLUDE` and `#endregion EXCLUDE` tags in a listing, even if these are within two `INCLUDE` tags, this section is omitted from being visible in the book and replaced with a `// ...` just to try and bring more clarity to the point that is actually being taught in that listing. | ||
In addition, any line that ends with a `// EXCLUDE` is a line that is omitted from being seen in the book. | ||
## Questions/Bugs | ||
|
||
If you have any questions or find any bugs, please feel free to open a [Discussion](https://github.com/IntelliTect/EssentialCSharp/discussions), [Pull Request](https://github.com/IntelliTect/EssentialCSharp/pulls), or [Issue](https://github.com/IntelliTect/EssentialCSharp/discussions). | ||
If there is an issue with [EssentialCSharp.com](EssentialCSharp.com), please checkout the [EssentialCSharp.Web Repository](https://github.com/IntelliTect/EssentialCSharp.Web) | ||
To run all the tests, run `dotnet test` on the command prompt in the EssentialCSharp solution directory on your local computer. | ||
## Happy Coding |
Oops, something went wrong.