diff --git a/Books.ConsoleApp.sln b/Books.ConsoleApp.sln index 75582c1..8b910ea 100644 --- a/Books.ConsoleApp.sln +++ b/Books.ConsoleApp.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29509.3 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Books.Console", "Books.ConsoleApp\Books.Console.csproj", "{A09D7905-08C5-41F3-ADE6-2037471A2403}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Books.ConsoleApp", "Books.ConsoleApp\Books.ConsoleApp.csproj", "{A09D7905-08C5-41F3-ADE6-2037471A2403}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demos", "Demos\Demos.csproj", "{4D24A90A-EE2D-4408-B922-075C8E32882A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {A09D7905-08C5-41F3-ADE6-2037471A2403}.Debug|Any CPU.Build.0 = Debug|Any CPU {A09D7905-08C5-41F3-ADE6-2037471A2403}.Release|Any CPU.ActiveCfg = Release|Any CPU {A09D7905-08C5-41F3-ADE6-2037471A2403}.Release|Any CPU.Build.0 = Release|Any CPU + {4D24A90A-EE2D-4408-B922-075C8E32882A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4D24A90A-EE2D-4408-B922-075C8E32882A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4D24A90A-EE2D-4408-B922-075C8E32882A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4D24A90A-EE2D-4408-B922-075C8E32882A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Books.ConsoleApp/Books.Console.csproj b/Books.ConsoleApp/Books.ConsoleApp.csproj similarity index 86% rename from Books.ConsoleApp/Books.Console.csproj rename to Books.ConsoleApp/Books.ConsoleApp.csproj index 73c52f8..490dc79 100644 --- a/Books.ConsoleApp/Books.Console.csproj +++ b/Books.ConsoleApp/Books.ConsoleApp.csproj @@ -10,7 +10,6 @@ - diff --git a/Books.ConsoleApp/Program.cs b/Books.ConsoleApp/Program.cs index 93964e3..9df9b2b 100644 --- a/Books.ConsoleApp/Program.cs +++ b/Books.ConsoleApp/Program.cs @@ -5,7 +5,7 @@ using System.Globalization; using System.Linq; using Books.ConsoleApp; -namespace Books.Console +namespace Books.ConsoleApp { class Program { diff --git a/Demos/DemoAction.cs b/Demos/DemoAction.cs new file mode 100644 index 0000000..a5a79f0 --- /dev/null +++ b/Demos/DemoAction.cs @@ -0,0 +1,31 @@ +using System; + +public class DemoAction +{ + private Action justAnAction; + + private Action AsAction() + { + var name = typeof(T).Name; + return v => Console.WriteLine(name); + } + + private void ContrivedMethod() + { + var willTakeString = AsAction(); + + willTakeString("Hello world"); + // outputs: String + + //type safety - squiggly + willTakeString("1"); + } + + Action takesString; // and does stuff with it + Action takesIntAndString; // and does stuff with it + + Action takesAnyObject; + + Action takesMaximum; + // I've never used so many - so don't worry +} diff --git a/Demos/DemoFunc.cs b/Demos/DemoFunc.cs new file mode 100644 index 0000000..95e313c --- /dev/null +++ b/Demos/DemoFunc.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class DemoFunc +{ + private Func intFunc; + + private Func AsFunc(T input) + { + return () => input; + } + + private T Exec(Func func) + { + return func(); + } + + + public void ContrivedMethod() + { + Func helloWorldFunc = AsFunc("Hello World!"); + var helloWorld = Exec(helloWorldFunc); + // helloWorld == "Hello World!" + + intFunc = AsFunc(1); + var one = Exec(intFunc); + // one == 1); + } + + + public void SomewhatMoreRealisticMethod() + { + // cant use var - because we need to tell the compiler what we'll describe + Func, string, bool> authorExists = + (booksByAuthor, authorName) => booksByAuthor.Any(ba => ba.Author == authorName); + + + Func, string, BooksByAuthor> getGataloguedAuthor = + (booksByAuthor, authorName) => { + // can do complex stuff or help in debugging + return booksByAuthor.FirstOrDefault(ba => ba.Author == authorName); + }; + + + var bas = Enumerable.Empty();// for conciceness + + var exits = authorExists(bas, "Homer"); + + var homersBooks = getGataloguedAuthor(bas, "Homer"); + } +} diff --git a/Demos/Demos.csproj b/Demos/Demos.csproj new file mode 100644 index 0000000..967bb6b --- /dev/null +++ b/Demos/Demos.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.0 + + + + + + + diff --git a/Demos/Program.cs b/Demos/Program.cs new file mode 100644 index 0000000..bdd2103 --- /dev/null +++ b/Demos/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Demos +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +}