Initial commit

This commit is contained in:
Mark J Price 2022-02-28 20:09:20 +00:00
parent d0eb68594c
commit c0d4d11b54
24 changed files with 463 additions and 0 deletions

View file

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>
<ItemGroup>
<Using Remove="System" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="packt.csdotnet.sharedlibrary" Version="7.0.0" />
<PackageReference Include="dialectsoftware.collections.matrix" Version="1.0.0" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,53 @@
using System.Xml.Linq; // XDocument
using System; // String
using Packt.Shared; // IsValidHex(), IsValidXmlTag(), IsValidPassword()
using DialectSoftware.Collections;
using DialectSoftware.Collections.Generics;
XDocument doc = new();
string s1 = "Hello";
String s2 = "World";
WriteLine($"{s1} {s2}");
Write("Enter a color value in hex: ");
string? hex = ReadLine(); // or "00ffc8"
WriteLine("Is {0} a valid color value? {1}",
arg0: hex, arg1: hex.IsValidHex());
Write("Enter a XML element: ");
string? xmlTag = ReadLine(); // or "<h1 class=\"<\" />"
WriteLine("Is {0} a valid XML element? {1}",
arg0: xmlTag, arg1: xmlTag.IsValidXmlTag());
Write("Enter a password: ");
string? password = ReadLine(); // or "secretsauce"
WriteLine("Is {0} a valid password? {1}",
arg0: password, arg1: password.IsValidPassword());
Axis x = new("x", 0, 10, 1);
Axis y = new("y", 0, 4, 1);
Matrix<long> matrix = new(new[] { x, y });
for (int i = 0; i < matrix.Axes[0].Points.Length; i++)
{
matrix.Axes[0].Points[i].Label = "x" + i.ToString();
}
for (int i = 0; i < matrix.Axes[1].Points.Length; i++)
{
matrix.Axes[1].Points[i].Label = "y" + i.ToString();
}
foreach (long[] c in matrix)
{
matrix[c] = c[0] + c[1];
}
foreach (long[] c in matrix)
{
WriteLine("{0},{1} ({2},{3}) = {4}",
matrix.Axes[0].Points[c[0]].Label,
matrix.Axes[1].Points[c[1]].Label,
c[0], c[1], matrix[c]);
}

View file

@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32210.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssembliesAndNamespaces", "AssembliesAndNamespaces\AssembliesAndNamespaces.csproj", "{4FD636C5-91F6-46AC-97B7-2396F11A31A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedLibrary", "SharedLibrary\SharedLibrary.csproj", "{EDEB4531-EE20-440B-BB41-84CDA5715BA7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetEverywhere", "DotNetEverywhere\DotNetEverywhere.csproj", "{7509E104-A3AE-4AEB-9656-D83A15D5CD70}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ControlSDK", "ControlSDK\ControlSDK.csproj", "{76808C33-E138-4170-9621-122C1993B36E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4FD636C5-91F6-46AC-97B7-2396F11A31A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FD636C5-91F6-46AC-97B7-2396F11A31A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FD636C5-91F6-46AC-97B7-2396F11A31A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FD636C5-91F6-46AC-97B7-2396F11A31A8}.Release|Any CPU.Build.0 = Release|Any CPU
{EDEB4531-EE20-440B-BB41-84CDA5715BA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDEB4531-EE20-440B-BB41-84CDA5715BA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDEB4531-EE20-440B-BB41-84CDA5715BA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDEB4531-EE20-440B-BB41-84CDA5715BA7}.Release|Any CPU.Build.0 = Release|Any CPU
{7509E104-A3AE-4AEB-9656-D83A15D5CD70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7509E104-A3AE-4AEB-9656-D83A15D5CD70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7509E104-A3AE-4AEB-9656-D83A15D5CD70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7509E104-A3AE-4AEB-9656-D83A15D5CD70}.Release|Any CPU.Build.0 = Release|Any CPU
{76808C33-E138-4170-9621-122C1993B36E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76808C33-E138-4170-9621-122C1993B36E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76808C33-E138-4170-9621-122C1993B36E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76808C33-E138-4170-9621-122C1993B36E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {86EB53C2-864D-4ACE-91FC-C09189FDA62D}
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,5 @@
namespace ControlSDK;
public class Class1
{
}

View file

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,5 @@
{
"sdk": {
"version": "6.0.200"
}
}

View file

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RuntimeIdentifiers>
win10-x64;osx-x64;osx.11.0-arm64;linux-x64;linux-arm64
</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,21 @@
WriteLine("I can run everywhere!");
WriteLine($"OS Version is {Environment.OSVersion}.");
if (OperatingSystem.IsMacOS())
{
WriteLine("I am macOS.");
}
else if (OperatingSystem.IsWindowsVersionAtLeast(major: 10, build: 22000))
{
WriteLine("I am Windows 11.");
}
else if (OperatingSystem.IsWindowsVersionAtLeast(major: 10))
{
WriteLine("I am Windows 10.");
}
else
{
WriteLine("I am some other mysterious OS.");
}
WriteLine("Press ENTER to stop me.");
ReadLine();

View file

@ -0,0 +1,5 @@
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r osx-x64
dotnet publish -c Release -r osx.11.0-arm64
dotnet publish -c Release -r linux-x64
dotnet publish -c Release -r linux-arm64

View file

@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>Packt.CSdotnet.SharedLibrary</PackageId>
<PackageVersion>7.0.0.0</PackageVersion>
<Title>C# 11 and .NET 7 Shared Library</Title>
<Authors>Mark J Price</Authors>
<PackageLicenseExpression>
MS-PL
</PackageLicenseExpression>
<PackageProjectUrl>
https://github.com/markjprice/cs11dotnet7
</PackageProjectUrl>
<PackageIcon>packt-csdotnet-sharedlibrary.png</PackageIcon>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>
Example shared library packaged for NuGet.
</PackageReleaseNotes>
<Description>
Three extension methods to validate a string value.
</Description>
<Copyright>
Copyright © 2016-2022 Packt Publishing Limited
</Copyright>
<PackageTags>string extensions packt csharp dotnet</PackageTags>
</PropertyGroup>
<ItemGroup>
<None Include="packt-csdotnet-sharedlibrary.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>

View file

@ -0,0 +1,26 @@
using System.Text.RegularExpressions;
namespace Packt.Shared
{
public static class StringExtensions
{
public static bool IsValidXmlTag(this string input)
{
return Regex.IsMatch(input,
@"^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$");
}
public static bool IsValidPassword(this string input)
{
// minimum of eight valid characters
return Regex.IsMatch(input, "^[a-zA-Z0-9_-]{8,}$");
}
public static bool IsValidHex(this string input)
{
// three or six valid hex number characters
return Regex.IsMatch(input,
"^#?([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$");
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>
<ItemGroup>
<Using Remove="System" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="packt.csdotnet.sharedlibrary" Version="7.0.0" />
<PackageReference Include="dialectsoftware.collections.matrix" Version="1.0.0" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,53 @@
using System.Xml.Linq; // XDocument
using System; // String
using Packt.Shared; // IsValidHex(), IsValidXmlTag(), IsValidPassword()
using DialectSoftware.Collections;
using DialectSoftware.Collections.Generics;
XDocument doc = new();
string s1 = "Hello";
String s2 = "World";
WriteLine($"{s1} {s2}");
Write("Enter a color value in hex: ");
string? hex = ReadLine(); // or "00ffc8"
WriteLine("Is {0} a valid color value? {1}",
arg0: hex, arg1: hex.IsValidHex());
Write("Enter a XML element: ");
string? xmlTag = ReadLine(); // or "<h1 class=\"<\" />"
WriteLine("Is {0} a valid XML element? {1}",
arg0: xmlTag, arg1: xmlTag.IsValidXmlTag());
Write("Enter a password: ");
string? password = ReadLine(); // or "secretsauce"
WriteLine("Is {0} a valid password? {1}",
arg0: password, arg1: password.IsValidPassword());
Axis x = new("x", 0, 10, 1);
Axis y = new("y", 0, 4, 1);
Matrix<long> matrix = new(new[] { x, y });
for (int i = 0; i < matrix.Axes[0].Points.Length; i++)
{
matrix.Axes[0].Points[i].Label = "x" + i.ToString();
}
for (int i = 0; i < matrix.Axes[1].Points.Length; i++)
{
matrix.Axes[1].Points[i].Label = "y" + i.ToString();
}
foreach (long[] c in matrix)
{
matrix[c] = c[0] + c[1];
}
foreach (long[] c in matrix)
{
WriteLine("{0},{1} ({2},{3}) = {4}",
matrix.Axes[0].Points[c[0]].Label,
matrix.Axes[1].Points[c[1]].Label,
c[0], c[1], matrix[c]);
}

View file

@ -0,0 +1,16 @@
{
"folders": [
{
"path": "AssembliesAndNamespaces"
},
{
"path": "SharedLibrary"
},
{
"path": "ControlSDK"
},
{
"path": "DotNetEverywhere"
}
]
}

View file

@ -0,0 +1,5 @@
namespace ControlSDK;
public class Class1
{
}

View file

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,5 @@
{
"sdk": {
"version": "6.0.200"
}
}

View file

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RuntimeIdentifiers>
win10-x64;osx-x64;osx.11.0-arm64;linux-x64;linux-arm64
</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<Using Include="System.Console" Static="true" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,21 @@
WriteLine("I can run everywhere!");
WriteLine($"OS Version is {Environment.OSVersion}.");
if (OperatingSystem.IsMacOS())
{
WriteLine("I am macOS.");
}
else if (OperatingSystem.IsWindowsVersionAtLeast(major: 10, build: 22000))
{
WriteLine("I am Windows 11.");
}
else if (OperatingSystem.IsWindowsVersionAtLeast(major: 10))
{
WriteLine("I am Windows 10.");
}
else
{
WriteLine("I am some other mysterious OS.");
}
WriteLine("Press ENTER to stop me.");
ReadLine();

View file

@ -0,0 +1,5 @@
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r osx-x64
dotnet publish -c Release -r osx.11.0-arm64
dotnet publish -c Release -r linux-x64
dotnet publish -c Release -r linux-arm64

View file

@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>Packt.CSdotnet.SharedLibrary</PackageId>
<PackageVersion>7.0.0.0</PackageVersion>
<Title>C# 11 and .NET 7 Shared Library</Title>
<Authors>Mark J Price</Authors>
<PackageLicenseExpression>
MS-PL
</PackageLicenseExpression>
<PackageProjectUrl>
https://github.com/markjprice/cs11dotnet7
</PackageProjectUrl>
<PackageIcon>packt-csdotnet-sharedlibrary.png</PackageIcon>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>
Example shared library packaged for NuGet.
</PackageReleaseNotes>
<Description>
Three extension methods to validate a string value.
</Description>
<Copyright>
Copyright © 2016-2022 Packt Publishing Limited
</Copyright>
<PackageTags>string extensions packt csharp dotnet</PackageTags>
</PropertyGroup>
<ItemGroup>
<None Include="packt-csdotnet-sharedlibrary.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>

View file

@ -0,0 +1,26 @@
using System.Text.RegularExpressions;
namespace Packt.Shared
{
public static class StringExtensions
{
public static bool IsValidXmlTag(this string input)
{
return Regex.IsMatch(input,
@"^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$");
}
public static bool IsValidPassword(this string input)
{
// minimum of eight valid characters
return Regex.IsMatch(input, "^[a-zA-Z0-9_-]{8,}$");
}
public static bool IsValidHex(this string input)
{
// three or six valid hex number characters
return Regex.IsMatch(input,
"^#?([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$");
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB