Initial commit

This commit is contained in:
Mark J Price 2022-09-17 16:33:54 +01:00
parent 04b31e6eb8
commit 5108079993
26 changed files with 123 additions and 38 deletions

View file

@ -3,22 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32210.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PacktLibrary", "PacktLibrary\PacktLibrary.csproj", "{9E796C3B-6FF6-4E0A-8B6D-A591B6FD1308}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PeopleApp", "PeopleApp\PeopleApp.csproj", "{DF7885A2-C9F1-4959-9D13-C72E5E77CCDA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Namespaces", "Namespaces\Namespaces.csproj", "{AA8F156C-1105-4AB2-8C42-637990E44EB4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PacktLibraryNetStandard2", "PacktLibraryNetStandard2\PacktLibraryNetStandard2.csproj", "{8E856A85-0B5E-4374-A35A-B53B94834DBA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PacktLibraryModern", "PacktLibraryModern\PacktLibraryModern.csproj", "{1981F355-34EE-4934-ABA1-CA6119ED5D99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9E796C3B-6FF6-4E0A-8B6D-A591B6FD1308}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E796C3B-6FF6-4E0A-8B6D-A591B6FD1308}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E796C3B-6FF6-4E0A-8B6D-A591B6FD1308}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E796C3B-6FF6-4E0A-8B6D-A591B6FD1308}.Release|Any CPU.Build.0 = Release|Any CPU
{DF7885A2-C9F1-4959-9D13-C72E5E77CCDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF7885A2-C9F1-4959-9D13-C72E5E77CCDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF7885A2-C9F1-4959-9D13-C72E5E77CCDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -27,6 +25,14 @@ Global
{AA8F156C-1105-4AB2-8C42-637990E44EB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA8F156C-1105-4AB2-8C42-637990E44EB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA8F156C-1105-4AB2-8C42-637990E44EB4}.Release|Any CPU.Build.0 = Release|Any CPU
{8E856A85-0B5E-4374-A35A-B53B94834DBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E856A85-0B5E-4374-A35A-B53B94834DBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E856A85-0B5E-4374-A35A-B53B94834DBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E856A85-0B5E-4374-A35A-B53B94834DBA}.Release|Any CPU.Build.0 = Release|Any CPU
{1981F355-34EE-4934-ABA1-CA6119ED5D99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1981F355-34EE-4934-ABA1-CA6119ED5D99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1981F355-34EE-4934-ABA1-CA6119ED5D99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1981F355-34EE-4934-ABA1-CA6119ED5D99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -1,8 +0,0 @@
namespace Packt.Shared;
public class Book
{
// required is not working in .NET 7 Preview 1
public /* required */ string? Isbn { get; set; }
public string? Title { get; set; }
}

View file

@ -0,0 +1,22 @@
using System.Diagnostics.CodeAnalysis; // [SetsRequiredMembers]
namespace Packt.Shared;
public class Book
{
public Book() { } // For use with initialization syntax.
[SetsRequiredMembers]
public Book(string isbn, string title)
{
Isbn = isbn;
Title = title;
}
// Needs .NET 7 or later as well as C# 11 or later.
public required string? Isbn { get; set; }
public required string? Title { get; set; }
public string? Author { get; set; }
public int PageCount { get; set; }
}

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>
</Project>

View file

@ -2,10 +2,10 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />

View file

@ -8,7 +8,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PacktLibrary\PacktLibrary.csproj" />
<ProjectReference Include="..\PacktLibraryModern\PacktLibraryModern.csproj" />
<ProjectReference Include="..\PacktLibraryNetStandard2\PacktLibraryNetStandard2.csproj" />
</ItemGroup>
<ItemGroup>

View file

@ -161,8 +161,21 @@ WriteLine($"Sam's favorite ice-cream flavor is {sam.FavoriteIceCream}.");
sam.FavoritePrimaryColor = "Red";
WriteLine($"Sam's favorite primary color is {sam.FavoritePrimaryColor}.");
Book book = new();
book.Title = "C# 11 and .NET 7 - Modern Cross-Platform Development";
/*
Book book = new()
{
Isbn = "978-1803237800",
Title = "C# 11 and .NET 7 - Modern Cross-Platform Development Fundamentals"
};
*/
Book book = new(isbn: "978-1803237800",
title: "C# 11 and .NET 7 - Modern Cross-Platform Development Fundamentals");
book.Author = "Mark J. Price";
book.PageCount = 821;
WriteLine("{0}: {1} written by {2} has {3:N0} pages.",
book.Isbn, book.Title, book.Author, book.PageCount);
sam.Children.Add(new() { Name = "Charlie", DateOfBirth = new(2010, 3, 18) });
sam.Children.Add(new() { Name = "Ella", DateOfBirth = new(2020, 12, 24) });
@ -235,7 +248,7 @@ Passenger[] passengers = {
new CoachClassPassenger { CarryOnKG = 0, Name = "Amit" },
};
foreach (object passenger in passengers)
foreach (Passenger passenger in passengers)
{
decimal flightCost = passenger switch
{

View file

@ -1,13 +1,16 @@
{
"folders": [
{
"path": "PacktLibrary"
"path": "PacktLibraryNetStandard2"
},
{
"path": "PeopleApp"
"path": "PacktLibraryModern"
},
{
"path": "Namespaces"
},
{
"path": "PeopleApp"
}
]
}

View file

@ -1,8 +0,0 @@
namespace Packt.Shared;
public class Book
{
// required is not working in .NET 7 Preview 1
public /* required */ string? Isbn { get; set; }
public string? Title { get; set; }
}

View file

@ -0,0 +1,22 @@
using System.Diagnostics.CodeAnalysis; // [SetsRequiredMembers]
namespace Packt.Shared;
public class Book
{
public Book() { } // For use with initialization syntax.
[SetsRequiredMembers]
public Book(string isbn, string title)
{
Isbn = isbn;
Title = title;
}
// Needs .NET 7 or later as well as C# 11 or later.
public required string? Isbn { get; set; }
public required string? Title { get; set; }
public string? Author { get; set; }
public int PageCount { get; set; }
}

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>
</Project>

View file

@ -2,10 +2,10 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />

View file

@ -8,7 +8,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PacktLibrary\PacktLibrary.csproj" />
<ProjectReference Include="..\PacktLibraryModern\PacktLibraryModern.csproj" />
<ProjectReference Include="..\PacktLibraryNetStandard2\PacktLibraryNetStandard2.csproj" />
</ItemGroup>
<ItemGroup>

View file

@ -161,8 +161,21 @@ WriteLine($"Sam's favorite ice-cream flavor is {sam.FavoriteIceCream}.");
sam.FavoritePrimaryColor = "Red";
WriteLine($"Sam's favorite primary color is {sam.FavoritePrimaryColor}.");
Book book = new();
book.Title = "C# 11 and .NET 7 - Modern Cross-Platform Development";
/*
Book book = new()
{
Isbn = "978-1803237800",
Title = "C# 11 and .NET 7 - Modern Cross-Platform Development Fundamentals"
};
*/
Book book = new(isbn: "978-1803237800",
title: "C# 11 and .NET 7 - Modern Cross-Platform Development Fundamentals");
book.Author = "Mark J. Price";
book.PageCount = 821;
WriteLine("{0}: {1} written by {2} has {3:N0} pages.",
book.Isbn, book.Title, book.Author, book.PageCount);
sam.Children.Add(new() { Name = "Charlie", DateOfBirth = new(2010, 3, 18) });
sam.Children.Add(new() { Name = "Ella", DateOfBirth = new(2020, 12, 24) });
@ -235,7 +248,7 @@ Passenger[] passengers = {
new CoachClassPassenger { CarryOnKG = 0, Name = "Amit" },
};
foreach (object passenger in passengers)
foreach (Passenger passenger in passengers)
{
decimal flightCost = passenger switch
{