diff --git a/samples/.idea/.idea.samples/.idea/.gitignore b/samples/.idea/.idea.samples/.idea/.gitignore new file mode 100644 index 0000000..59845a9 --- /dev/null +++ b/samples/.idea/.idea.samples/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/modules.xml +/projectSettingsUpdater.xml +/.idea.samples.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/samples/.idea/.idea.samples/.idea/encodings.xml b/samples/.idea/.idea.samples/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/samples/.idea/.idea.samples/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/samples/.idea/.idea.samples/.idea/indexLayout.xml b/samples/.idea/.idea.samples/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/samples/.idea/.idea.samples/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/samples/.idea/.idea.samples/.idea/vcs.xml b/samples/.idea/.idea.samples/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/samples/.idea/.idea.samples/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/samples/CS10/Program.cs b/samples/CS10/Program.cs index c931922..dbfcd97 100644 --- a/samples/CS10/Program.cs +++ b/samples/CS10/Program.cs @@ -1,4 +1,6 @@ -namespace CS10 { +// ReSharper disable All + +namespace CS10 { class Program { // Nested types, just like the C# 8 sample: public class Address { @@ -13,13 +15,10 @@ static void Main(string[] args) { // Nested property patterns, now shorter: - var customer = new Customer - { - Address = new Address { City = "Castle Douglas", Country = "UK" } - }; + var customer = new Customer { Address = new Address { City = "Castle Douglas", Country = "UK" } }; if (customer is { Address.City: "Castle Douglas" }) { Console.WriteLine("This customer lives around the corner"); } } } -} +} \ No newline at end of file diff --git a/samples/CS11/Program.cs b/samples/CS11/Program.cs index 50afaed..ccbc4f8 100644 --- a/samples/CS11/Program.cs +++ b/samples/CS11/Program.cs @@ -1,4 +1,6 @@ -namespace CS11 { +// ReSharper disable All + +namespace CS11 { class Program { static void Main(string[] args) { int[] numbers = { 1, 3, 42 }; @@ -40,10 +42,9 @@ } // Now we're talking - static int Sum(int[] l) => l switch - { + static int Sum(int[] l) => l switch { [] => 0, [var x, .. var xs] => x + Sum(xs) }; } -} +} \ No newline at end of file diff --git a/samples/CS7/Program.cs b/samples/CS7/Program.cs index 32f2b1b..793eced 100644 --- a/samples/CS7/Program.cs +++ b/samples/CS7/Program.cs @@ -1,4 +1,6 @@ -namespace CS7 { +// ReSharper disable All + +namespace CS7 { public class DeadPerson { public string Name { get; init; } = ""; public virtual bool IsAlive => false; @@ -34,6 +36,5 @@ Console.WriteLine("My heartfelt apologies in case anybody finds my zombie sample offensive."); } - } } \ No newline at end of file diff --git a/samples/CS8/Program.cs b/samples/CS8/Program.cs index 5e68f0d..83a574f 100644 --- a/samples/CS8/Program.cs +++ b/samples/CS8/Program.cs @@ -1,8 +1,9 @@ -namespace CS8 { +// ReSharper disable All + +namespace CS8 { class Program { // This is a "switch expression" - static int CalcResult(int input) => input switch - { + static int CalcResult(int input) => input switch { 1 => 2, 2 => 3, _ => throw new ArgumentException("Rien ne va plus") @@ -33,13 +34,10 @@ Console.WriteLine($"Found Oli, his last name is {olisLastName}."); // Nested property patterns: - var customer = new Customer - { - Address = new Address { City = "Castle Douglas", Country = "UK" } - }; + var customer = new Customer { Address = new Address { City = "Castle Douglas", Country = "UK" } }; if (customer is { Address: { City: "Castle Douglas" } }) { Console.WriteLine("This customer lives around the corner"); } } } -} +} \ No newline at end of file diff --git a/samples/CS9/Program.cs b/samples/CS9/Program.cs index 619d3d3..3968700 100644 --- a/samples/CS9/Program.cs +++ b/samples/CS9/Program.cs @@ -1,19 +1,23 @@ -namespace CS9 { +// ReSharper disable All + +namespace CS9 { class Program { // Relational patterns (>= operator et al.) // Logical patterns ("or", also "and" and "not") // Note: parens ( and ) can be used to determine precedence bool IsPastMidYear(DateTime dt) => dt is { Month: >= 7 }; bool IsThisYearOrLast(DateTime dt) => dt is { Year: 2022 or 2021 }; + bool IsSummer(DateTime dt) => dt is - { Month: 7 or 8 } or - { Month: 6, Day: >= 21 } or - { Month: 9, Day: < 21 }; + { Month: 7 or 8 } or + { Month: 6, Day: >= 21 } or + { Month: 9, Day: < 21 }; // Class with "Deconstruct" implementation class Order { public int ItemCount { get; set; } public double ItemPrice { get; set; } + public void Deconstruct(out int itemCount, out double itemPrice) { itemCount = ItemCount; itemPrice = ItemPrice; @@ -24,17 +28,16 @@ ValuableDueToHighCount, ValuableDueToHighItemPrice, ValuableDueToHighTotal, - NotValuable, + NotValuable } // Positional patterns with placeholders - note that // the element lists must be "complete"! static OrderValue OrderValueCategory(Order o) => - o switch - { - ( < 0, _) => throw new ArgumentException("Positive itemCounts please!"), + o switch { + (< 0, _) => throw new ArgumentException("Positive itemCounts please!"), (_, < 0) => throw new ArgumentException("Positive itemPrices please!"), - ( >= 100, _) => OrderValue.ValuableDueToHighCount, + (>= 100, _) => OrderValue.ValuableDueToHighCount, (_, >= 1000) => OrderValue.ValuableDueToHighItemPrice, // Assign variable names for further processing @@ -47,4 +50,4 @@ static void Main(string[] args) { } } -} +} \ No newline at end of file diff --git a/samples/fpsamples/sample4.fs b/samples/fpsamples/sample4.fs index 1d77809..7173b1a 100644 --- a/samples/fpsamples/sample4.fs +++ b/samples/fpsamples/sample4.fs @@ -1,4 +1,4 @@ -// In F# the keywoard `match` can be used to run an +// In F# the keyword `match` can be used to run an // explicit pattern match. let rec listLength l = diff --git a/samples/samples.sln b/samples/samples.sln new file mode 100644 index 0000000..4d4d035 --- /dev/null +++ b/samples/samples.sln @@ -0,0 +1,46 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CS7", "CS7\CS7.csproj", "{90F0E6BB-4562-4F69-8DBA-95C1D01B5F7D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CS8", "CS8\CS8.csproj", "{D70FEF23-B303-431F-9A14-0F4478DFDAE7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CS9", "CS9\CS9.csproj", "{72390EA1-3D7A-4014-9AAC-2A4EED652350}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CS10", "CS10\CS10.csproj", "{ACDEF545-04C1-4F2D-96E3-041B3A2151B3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CS11", "CS11\CS11.csproj", "{D1B3E6C4-303A-4A76-B555-4D78E50F8957}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {90F0E6BB-4562-4F69-8DBA-95C1D01B5F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90F0E6BB-4562-4F69-8DBA-95C1D01B5F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90F0E6BB-4562-4F69-8DBA-95C1D01B5F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90F0E6BB-4562-4F69-8DBA-95C1D01B5F7D}.Release|Any CPU.Build.0 = Release|Any CPU + {D70FEF23-B303-431F-9A14-0F4478DFDAE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D70FEF23-B303-431F-9A14-0F4478DFDAE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D70FEF23-B303-431F-9A14-0F4478DFDAE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D70FEF23-B303-431F-9A14-0F4478DFDAE7}.Release|Any CPU.Build.0 = Release|Any CPU + {72390EA1-3D7A-4014-9AAC-2A4EED652350}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {72390EA1-3D7A-4014-9AAC-2A4EED652350}.Debug|Any CPU.Build.0 = Debug|Any CPU + {72390EA1-3D7A-4014-9AAC-2A4EED652350}.Release|Any CPU.ActiveCfg = Release|Any CPU + {72390EA1-3D7A-4014-9AAC-2A4EED652350}.Release|Any CPU.Build.0 = Release|Any CPU + {ACDEF545-04C1-4F2D-96E3-041B3A2151B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ACDEF545-04C1-4F2D-96E3-041B3A2151B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ACDEF545-04C1-4F2D-96E3-041B3A2151B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ACDEF545-04C1-4F2D-96E3-041B3A2151B3}.Release|Any CPU.Build.0 = Release|Any CPU + {D1B3E6C4-303A-4A76-B555-4D78E50F8957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1B3E6C4-303A-4A76-B555-4D78E50F8957}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1B3E6C4-303A-4A76-B555-4D78E50F8957}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1B3E6C4-303A-4A76-B555-4D78E50F8957}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal