-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved anonymous type samples to alternates and created tuple implemen…
…tations.
- Loading branch information
1 parent
b4c62d8
commit 500d7ac
Showing
10 changed files
with
222 additions
and
22 deletions.
There are no files selected for viewing
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
src/Chapter15.Tests/Listing15.03A.AnonymousTypesWithinQueryExpressions.Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using IntelliTect.TestTools.Console; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_03.Tests | ||
{ | ||
[TestClass] | ||
public class ProgramTests | ||
{ | ||
[TestMethod] | ||
public void ProjectionWithLinqsSelect() | ||
{ | ||
string expectedPattern = $@"{ Directory.GetCurrentDirectory() }{Path.DirectorySeparatorChar}*(*)"; | ||
|
||
string output = IntelliTect.TestTools.Console.ConsoleAssert.Execute(null, () => | ||
{ | ||
Program.ChapterMain(); | ||
}); | ||
|
||
IEnumerable<string> outputItems = output.Split('\n'); | ||
|
||
Assert.AreEqual(14, outputItems.Count()); | ||
foreach (string item in outputItems) | ||
{ | ||
Assert.IsTrue(item.IsLike(expectedPattern)); | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
35 changes: 35 additions & 0 deletions
35
src/Chapter15/Listing15.03.TuplesWithinQueryExpressions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_03 | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
public class Program | ||
{ | ||
public static void ChapterMain() | ||
{ | ||
List2(Directory.GetCurrentDirectory(), "*"); | ||
} | ||
|
||
static void List2(string rootDirectory, string searchPattern) | ||
{ | ||
var fileNames = Directory.EnumerateFiles( | ||
rootDirectory, searchPattern); | ||
var fileResults = | ||
from fileName in fileNames | ||
select | ||
( | ||
Name: fileName, | ||
LastWriteTime: File.GetLastWriteTime(fileName) | ||
); | ||
|
||
foreach (var fileResult in fileResults) | ||
{ | ||
Console.WriteLine( | ||
$@"{ fileResult.Name } ({ | ||
fileResult.LastWriteTime })"); | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...3.AnonymousTypesWithinQueryExpressions.cs → ...A.AnonymousTypesWithinQueryExpressions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Chapter15/Listing15.11A.SelectingAnAnonymousTypeFollowingTheGroupbyClause.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_11A | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
public class Program | ||
{ | ||
public static void ChapterMain() | ||
{ | ||
GroupKeywords1(); | ||
} | ||
|
||
private static void GroupKeywords1() | ||
{ | ||
IEnumerable<IGrouping<bool, string>> keywordGroups = | ||
from word in Keywords | ||
group word by word.Contains('*'); | ||
|
||
IEnumerable<(bool IsContextualKeyword, IGrouping<bool, string> Items)> selection = | ||
from groups in keywordGroups | ||
select | ||
( | ||
IsContextualKeyword: groups.Key, | ||
Items: groups | ||
); | ||
|
||
|
||
foreach ( | ||
(bool IsContextualKeyword, IGrouping<bool, string> Items) | ||
wordGroup in selection) | ||
{ | ||
|
||
Console.WriteLine(Environment.NewLine + "{0}:", | ||
wordGroup.IsContextualKeyword ? | ||
"Contextual Keywords" : "Keywords"); | ||
|
||
foreach (string keyword in wordGroup.Items) | ||
{ | ||
Console.Write(" " + keyword.Replace("*", null)); | ||
} | ||
} | ||
} | ||
|
||
private static string[] Keywords = { | ||
"abstract", "add*", "alias*", "as", "ascending*", | ||
"async*", "await*", "base","bool", "break", | ||
"by*", "byte", "case", "catch", "char", "checked", | ||
"class", "const", "continue", "decimal", "default", | ||
"delegate", "descending*", "do", "double", | ||
"dynamic*", "else", "enum", "event", "equals*", | ||
"explicit", "extern", "false", "finally", "fixed", | ||
"from*", "float", "for", "foreach", "get*", "global*", | ||
"group*", "goto", "if", "implicit", "in", "int", | ||
"into*", "interface", "internal", "is", "lock", "long", | ||
"join*", "let*", "nameof*", "namespace", "new", "null", | ||
"on*", "operator", "orderby*", "out", "override", | ||
"object", "params", "partial*", "private", "protected", | ||
"public", "readonly", "ref", "remove*", "return", "sbyte", | ||
"sealed", "select*", "set*", "short", "sizeof", | ||
"stackalloc", "static", "string", "struct", "switch", | ||
"this", "throw", "true", "try", "typeof", "uint", "ulong", | ||
"unsafe", "ushort", "using", "value*", "var*", "virtual", | ||
"unchecked", "void", "volatile", "where*", "while", "yield*" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Chapter15/Listing15.12A.SelectingAnonymousTypeWithoutTheQueryContinuation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_12 | ||
{ | ||
using System; | ||
using System.Linq; | ||
|
||
public class Program | ||
{ | ||
public static void ChapterMain() | ||
{ | ||
GroupKeywords1(); | ||
} | ||
|
||
private static void GroupKeywords1() | ||
{ | ||
var selection = | ||
from word in Keywords | ||
group word by word.Contains('*') | ||
into groups | ||
select new | ||
{ | ||
IsContextualKeyword = groups.Key, | ||
Items = groups | ||
}; | ||
|
||
foreach(var wordGroup in selection) | ||
{ | ||
Console.WriteLine(Environment.NewLine + "{0}:", | ||
wordGroup.IsContextualKeyword ? | ||
"Contextual Keywords" : "Keywords"); | ||
foreach(var keyword in wordGroup.Items) | ||
{ | ||
Console.Write(" " + | ||
keyword.Replace("*", null)); | ||
} | ||
} | ||
} | ||
|
||
private static string[] Keywords = { | ||
"abstract", "add*", "alias*", "as", "ascending*", | ||
"async*", "await*", "base","bool", "break", | ||
"by*", "byte", "case", "catch", "char", "checked", | ||
"class", "const", "continue", "decimal", "default", | ||
"delegate", "descending*", "do", "double", | ||
"dynamic*", "else", "enum", "event", "equals*", | ||
"explicit", "extern", "false", "finally", "fixed", | ||
"from*", "float", "for", "foreach", "get*", "global*", | ||
"group*", "goto", "if", "implicit", "in", "int", | ||
"into*", "interface", "internal", "is", "lock", "long", | ||
"join*", "let*", "nameof*", "namespace", "new", "null", | ||
"on*", "operator", "orderby*", "out", "override", | ||
"object", "params", "partial*", "private", "protected", | ||
"public", "readonly", "ref", "remove*", "return", "sbyte", | ||
"sealed", "select*", "set*", "short", "sizeof", | ||
"stackalloc", "static", "string", "struct", "switch", | ||
"this", "throw", "true", "try", "typeof", "uint", "ulong", | ||
"unsafe", "ushort", "using", "value*", "var*", "virtual", | ||
"unchecked", "void", "volatile", "where*", "while", "yield*" | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters