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,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