Skip to content

Commit 50b29a0

Browse files
Merge pull request #290 from IntelliTect/Chapter18Regions
Chapter18 regions
2 parents 3a3dc45 + 49c3a9f commit 50b29a0

File tree

30 files changed

+165
-70
lines changed

30 files changed

+165
-70
lines changed

src/Chapter18/Listing18.01.UsingTypeGetPropertiesToObtainAnObjectsPublicProperties.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ public class Program
77
{
88
public static void Main()
99
{
10+
#region INCLUDE
1011
DateTime dateTime = new DateTime();
1112

1213
Type type = dateTime.GetType();
1314
foreach(
1415
System.Reflection.PropertyInfo property in
15-
type.GetTypeInfo().GetProperties())
16+
type.GetProperties())
1617
{
1718
Console.WriteLine(property.Name);
1819
}
20+
#endregion INCLUDE
1921
}
2022
}
2123
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_02
22
{
33
using System;
4+
#region INCLUDE
45
using System.Diagnostics;
5-
6+
#region EXCLUDE
67
public class Program
78
{
89
public static void Main()
910
{
11+
#endregion EXCLUDE
1012
ThreadPriorityLevel priority;
1113
priority = (ThreadPriorityLevel)Enum.Parse(
1214
typeof(ThreadPriorityLevel), "Idle");
15+
//...
16+
#endregion INCLUDE
1317
}
1418
}
1519
}

src/Chapter18/Listing18.03.DynamicallyInvokingAMember.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_03
22
{
3+
#region INCLUDE
34
using System;
45
using System.Diagnostics;
56
using System.IO;
@@ -16,7 +17,7 @@ public static void Main(string[] args)
1617
Console.WriteLine(errorMessage);
1718
DisplayHelp();
1819
}
19-
else if(commandLine.Help || string.IsNullOrWhiteSpace(commandLine.Out))
20+
else if (commandLine.Help || string.IsNullOrWhiteSpace(commandLine.Out))
2021
{
2122
DisplayHelp();
2223
}
@@ -27,14 +28,15 @@ public static void Main(string[] args)
2728
{
2829
// Change thread priority
2930
}
31+
#region EXCLUDE
3032
Console.WriteLine(
3133
@$"Running {
3234
Path.GetFileName(Environment.GetCommandLineArgs()[0])} /Out:{
3335
commandLine.Out} /Priority:{
3436
commandLine.Priority}");
3537

38+
#endregion EXCLUDE
3639
}
37-
// ...
3840
}
3941

4042
private static void DisplayHelp()
@@ -66,9 +68,9 @@ public class CommandLineHandler
6668
{
6769
public static void Parse(string[] args, object commandLine)
6870
{
69-
if(!TryParse(args, commandLine, out string? errorMessage))
71+
if (!TryParse(args, commandLine, out string? errorMessage))
7072
{
71-
throw new Exception(errorMessage);
73+
throw new InvalidOperationException(errorMessage);
7274
}
7375
}
7476

@@ -87,6 +89,7 @@ public static bool TryParse(string[] args, object commandLine,
8789

8890
// Remove the slash|dash
8991
option = optionParts[0].Remove(0, 1);
92+
#region HIGHLIGHT
9093
PropertyInfo? property =
9194
commandLine.GetType().GetProperty(option,
9295
BindingFlags.IgnoreCase |
@@ -122,7 +125,8 @@ public static bool TryParse(string[] args, object commandLine,
122125
null);
123126
success = true;
124127
}
125-
catch(ArgumentException)
128+
#endregion HIGHLIGHT
129+
catch (ArgumentException)
126130
{
127131
success = false;
128132
errorMessage =
@@ -152,4 +156,5 @@ public static bool TryParse(string[] args, object commandLine,
152156
return success;
153157
}
154158
}
159+
#endregion INCLUDE
155160
}

src/Chapter18/Listing18.04.DeclaringTheStackClass.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_04
22
{
33
using System;
4-
4+
#region INCLUDE
55
public class Stack<T>
66
{
77
//...
@@ -13,4 +13,5 @@ public void Add(T i)
1313
}
1414
//...
1515
}
16+
#endregion INCLUDE
1617
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_05
22
{
3+
#region INCLUDE
34
using System;
4-
using System.Reflection;
55

66
public class Program
77
{
88
public static void Main()
99
{
1010
Type type;
1111
type = typeof(System.Nullable<>);
12-
Console.WriteLine(type.GetTypeInfo().ContainsGenericParameters);
13-
Console.WriteLine(type.GetTypeInfo().IsGenericType);
12+
Console.WriteLine(type.ContainsGenericParameters);
13+
Console.WriteLine(type.IsGenericType);
1414

1515
type = typeof(System.Nullable<DateTime>);
16-
Console.WriteLine(type.GetTypeInfo().ContainsGenericParameters);
17-
Console.WriteLine(type.GetTypeInfo().IsGenericType);
16+
Console.WriteLine(type.ContainsGenericParameters);
17+
Console.WriteLine(type.IsGenericType);
1818
}
1919
}
20+
#endregion INCLUDE
2021
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_06
22
{
3+
#region INCLUDE
34
using System;
45
using System.Collections.Generic;
5-
using System.Reflection;
66

77
public class Program
88
{
@@ -12,11 +12,13 @@ public static void Main()
1212

1313
Type t = s.GetType();
1414

15-
foreach(Type type in t.GetTypeInfo().GetGenericArguments())
15+
foreach(Type type in t.GetGenericArguments())
1616
{
1717
System.Console.WriteLine(
1818
"Type parameter: " + type.FullName);
1919
}
20+
//...
2021
}
2122
}
23+
#endregion INCLUDE
2224
}

src/Chapter18/Listing18.07.DynamicallyInvokingAMember.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_07
22
{
3+
#region INCLUDE
34
using System.ComponentModel;
45

56
public class Person : INotifyPropertyChanged
67
{
7-
// TODO: Update listing in Manuscript
88
public event PropertyChangedEventHandler? PropertyChanged;
99
public Person(string name)
1010
{
@@ -22,11 +22,14 @@ public string Name
2222
// Using C# 6.0 conditional null reference
2323
PropertyChanged?.Invoke(
2424
this,
25+
#region HIGHLIGHT
2526
new PropertyChangedEventArgs(
2627
nameof(Name)));
28+
#endregion HIGHLIGHT
2729
}
2830
}
2931
}
3032
// ...
3133
}
34+
#endregion INCLUDE
3235
}

src/Chapter18/Listing18.08.DecoratingAPropertyWithAnAttribute.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_08
22
{
33
using System;
4-
5-
class CommandLineInfo
4+
#region INCLUDE
5+
public class CommandLineInfo
66
{
7+
#region HIGHLIGHT
78
[CommandLineSwitchAlias("?")]
9+
#endregion HIGHLIGHT
810
public bool Help { get; set; }
911

12+
#region HIGHLIGHT
1013
[CommandLineSwitchRequired]
14+
#endregion HIGHLIGHT
1115
public string? Out { get; set; }
1216

1317
public System.Diagnostics.ProcessPriorityClass Priority
1418
{ get; set; } =
1519
System.Diagnostics.ProcessPriorityClass.Normal;
16-
17-
1820
}
21+
#endregion INCLUDE
1922
// Disabling warning since it is not implemented or shown in manuscript
20-
#pragma warning disable CA1018 // Mark attributes with AttributeUsageAttribute
23+
#pragma warning disable CA1018 // Mark attributes with AttributeUsageAttribute
2124
internal class CommandLineSwitchRequiredAttribute : Attribute
2225
{
2326
//not implemented

src/Chapter18/Listing18.09.DecoratingAPropertyWithMultipleAttributes.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_09
22
{
33
using System;
44

5-
class CommandLineInfo
5+
public class CommandLineInfo
66
{
77
[CommandLineSwitchAlias("?")]
88
public bool Help { get; set; }
99

1010
//Two Ways to do it
1111
//[CommandLineSwitchRequired]
1212
//[CommandLineSwitchAlias("FileName")]
13+
#region INCLUDE
1314
[CommandLineSwitchRequired,
1415
CommandLineSwitchAlias("FileName")]
1516
public string? Out { get; set; }
@@ -18,9 +19,10 @@ public System.Diagnostics.ProcessPriorityClass Priority
1819
{ get; set; } =
1920
System.Diagnostics.ProcessPriorityClass.Normal;
2021
}
22+
#endregion INCLUDE
2123

2224
// Disabling warning since it is not implemented or shown in manuscript
23-
#pragma warning disable CA1018 // Mark attributes with AttributeUsageAttribute
25+
#pragma warning disable CA1018 // Mark attributes with AttributeUsageAttribute
2426
internal class CommandLineSwitchRequiredAttribute : Attribute
2527
{
2628
//not implimented

src/Chapter18/Listing18.10.AssemblyAttributesWithinAssemblyInfo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Reflection;
1+
#region INCLUDE
2+
using System.Reflection;
23
using System.Runtime.CompilerServices;
34
using System.Runtime.InteropServices;
45

@@ -39,3 +40,4 @@
3940
// [assembly: AssemblyVersion("1.0.*")]
4041
[assembly: AssemblyVersion("1.0.0.0")]
4142
[assembly: AssemblyFileVersion("1.0.0.0")]
43+
#endregion INCLUDE

0 commit comments

Comments
 (0)