New Changes waiting
This commit is contained in:
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.29509.3
|
VisualStudioVersion = 16.0.29509.3
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{A09D7905-08C5-41F3-ADE6-2037471A2403}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NETCore.App" Version="2.2.8" />
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@ -5,7 +5,7 @@ using System.Globalization;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Books.ConsoleApp;
|
using Books.ConsoleApp;
|
||||||
|
|
||||||
namespace Books.Console
|
namespace Books.ConsoleApp
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
|||||||
31
Demos/DemoAction.cs
Normal file
31
Demos/DemoAction.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
public class DemoAction
|
||||||
|
{
|
||||||
|
private Action justAnAction;
|
||||||
|
|
||||||
|
private Action<T> AsAction<T>()
|
||||||
|
{
|
||||||
|
var name = typeof(T).Name;
|
||||||
|
return v => Console.WriteLine(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ContrivedMethod()
|
||||||
|
{
|
||||||
|
var willTakeString = AsAction<string>();
|
||||||
|
|
||||||
|
willTakeString("Hello world");
|
||||||
|
// outputs: String
|
||||||
|
|
||||||
|
//type safety - squiggly
|
||||||
|
willTakeString("1");
|
||||||
|
}
|
||||||
|
|
||||||
|
Action<string> takesString; // and does stuff with it
|
||||||
|
Action<int, string> takesIntAndString; // and does stuff with it
|
||||||
|
|
||||||
|
Action<object> takesAnyObject;
|
||||||
|
|
||||||
|
Action<int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int> takesMaximum;
|
||||||
|
// I've never used so many - so don't worry
|
||||||
|
}
|
||||||
52
Demos/DemoFunc.cs
Normal file
52
Demos/DemoFunc.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
public class DemoFunc
|
||||||
|
{
|
||||||
|
private Func<int> intFunc;
|
||||||
|
|
||||||
|
private Func<T> AsFunc<T>(T input)
|
||||||
|
{
|
||||||
|
return () => input;
|
||||||
|
}
|
||||||
|
|
||||||
|
private T Exec<T>(Func<T> func)
|
||||||
|
{
|
||||||
|
return func();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void ContrivedMethod()
|
||||||
|
{
|
||||||
|
Func<string> 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<IEnumerable<BooksByAuthor>, string, bool> authorExists =
|
||||||
|
(booksByAuthor, authorName) => booksByAuthor.Any(ba => ba.Author == authorName);
|
||||||
|
|
||||||
|
|
||||||
|
Func<IEnumerable<BooksByAuthor>, string, BooksByAuthor> getGataloguedAuthor =
|
||||||
|
(booksByAuthor, authorName) => {
|
||||||
|
// can do complex stuff or help in debugging
|
||||||
|
return booksByAuthor.FirstOrDefault(ba => ba.Author == authorName);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var bas = Enumerable.Empty<BooksByAuthor>();// for conciceness
|
||||||
|
|
||||||
|
var exits = authorExists(bas, "Homer");
|
||||||
|
|
||||||
|
var homersBooks = getGataloguedAuthor(bas, "Homer");
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Demos/Demos.csproj
Normal file
12
Demos/Demos.csproj
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Books.ConsoleApp\Books.ConsoleApp.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
12
Demos/Program.cs
Normal file
12
Demos/Program.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Demos
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user