Warnings through Table06.03
MODIFY
src/Chapter04.Tests/Listing04.38.Tests.cs
src/Chapter04.Tests/Listing04.38.Tests.cs
@@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_38.Tests
public class ProgramTests
{
[TestMethod]
- public void ChangeTemperatureWithoutConditionalOperature()
+ public void ChangeTemperatureWithoutConditionalOperator()
{
bool eventFired = false;
Thermostat thermostat = new Thermostat();
@@ -18,7 +18,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_38.Tests
Assert.IsTrue(eventFired);
}
- public void ChangeHumidityWithConditionalOperature()
+ public static void ChangeHumidityWithConditionalOperator()
{
bool eventFired = false;
Thermostat thermostat = new Thermostat();

MODIFY
src/Chapter05.Tests/Listing05.28.Tests.cs
src/Chapter05.Tests/Listing05.28.Tests.cs
@@ -5,8 +5,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_28.Tests
[TestClass]
public class LeveragingTryParseTests
{
- public static int OutValue = 0;
-
[TestMethod]
public void Main_InputNameAndAge35_AgeProperlyParsed()
{

MODIFY
src/Chapter05/Listing05.10.DeclaringATypeAlias.cs
src/Chapter05/Listing05.10.DeclaringATypeAlias.cs
#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_10
{
- using CountDownTimer = System.Threading.Timer;
+ using System;
+ using System.Threading;
+ using CountDownTimer = System.Timers.Timer;
public class HelloWorld
{

MODIFY
src/Chapter05/Listing05.11.DeclaringATypeAliasWithTheSameName.cs
src/Chapter05/Listing05.11.DeclaringATypeAliasWithTheSameName.cs
#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_11
{
- // Declare alias Console to refer to SubListing04_09.Console to
- // avoid code ambiguity with System.Console
- using Console = SubListing_04_09.Console;
+ using System;
+ using System.Threading;
+
+ // Declare alias Timer to refer to System.Timers.Timer to
+ // avoid code ambiguity with System.Threading.Timer
+ using Timer = System.Timers.Timer;
public class HelloWorld
{
public static void Main()
{
- Console console;
+ Timer timer;
// ...
}
}
}
-
-namespace SubListing_04_09
-{
- public class Console
- {
- public void Write(string message)
- {
-
- }
- }
-}

MODIFY
src/Chapter05/Listing05.12.PassingCommandLineArgumentsToMain.cs
src/Chapter05/Listing05.12.PassingCommandLineArgumentsToMain.cs
@@ -8,7 +8,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_12
public static int Main(string[] args)
{
int result;
-
switch(args.Length)
{
default:

MODIFY
src/Chapter06/Chapter06.csproj
src/Chapter06/Chapter06.csproj
<PropertyGroup>
<ChapterNumber>06</ChapterNumber>
</PropertyGroup>
+ <PropertyGroup>
+ <ExpectedWarnings>$(ExpectedWarnings),CA1507</ExpectedWarnings>
+ <!--
+ CA1507 Use nameof to express symbol names: Use nameof in place of string literal
+ -->
+ <IgnoredWarnings>$(IgnoredWarnings),IDE0079</IgnoredWarnings>
+ </PropertyGroup>
<Import Project="..\Chapter.props" />
<ItemGroup>
<Compile Remove="Listing06.24.CILCodeResultingFromProperties.cs" />

MODIFY
src/Chapter06/Listing06.41.AccessingAStaticField.cs
src/Chapter06/Listing06.41.AccessingAStaticField.cs
@@ -39,7 +39,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41
NextId++;
}
+ // Field wrapped into property later in chapter
+ #pragma warning disable CA2211 //Non-constant fields should not be visible
public static int NextId = 42;
+ #pragma warning disable CA2211
public int Id { get; private set; }
public string FirstName { get; set; }

MODIFY
src/Chapter06/Listing06.45.DeclaringAStaticClass.cs
src/Chapter06/Listing06.45.DeclaringAStaticClass.cs
@@ -11,9 +11,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45
// Check that there is at least one item in numbers
if(numbers.Length == 0)
{
- // In C# 6.0 replace "numbers" with nameof(numbers)
throw new ArgumentException(
- "numbers cannot be empty", "numbers");
+ "numbers cannot be empty", nameof(numbers));
}
int result;
@@ -34,9 +33,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45
// Check that there is at least one item in numbers
if(numbers.Length == 0)
{
- // In C# 6.0 replace "numbers" with nameof(numbers)
throw new ArgumentException(
- "numbers cannot be empty", "numbers");
+ "numbers cannot be empty", nameof(numbers));
}
int result;

MODIFY
src/Chapter06/Listing06.49.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs
src/Chapter06/Listing06.49.DeclaringAReadOnlyAutomaticallyImplementedProperty.cs
@@ -17,7 +17,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_49
class Program
{
- public void Main()
+ public static void Main()
{
// Note: board.Cells does not require initialization
TicTacToeBoard board = new TicTacToeBoard();

MODIFY
src/Chapter06/Listing06.53.DefiningAPartialMethodToAccessItsImplementation.cs
src/Chapter06/Listing06.53.DefiningAPartialMethodToAccessItsImplementation.cs
@@ -9,8 +9,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
public partial class Person
{
#region Extensibility Method Definitions
- partial void OnLastNameChanging(string value);
- partial void OnFirstNameChanging(string value);
+ static partial void OnLastNameChanging(string value);
+ static partial void OnFirstNameChanging(string value);
#endregion
// ...
@@ -54,38 +54,30 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
// File: Person.cs
partial class Person
{
- partial void OnLastNameChanging(string value)
+ static partial void OnLastNameChanging(string value)
{
if(value == null)
{
- // Use "value" rather than nameof(value)
- // prior to C# 6.0.
throw new ArgumentNullException(nameof(value));
}
if(value.Trim().Length == 0)
{
throw new ArgumentException(
"LastName cannot be empty.",
- // Use "value" rather than nameof(value)
- // prior to C# 6.0.
nameof(value));
}
}
- partial void OnFirstNameChanging(string value)
+ static partial void OnFirstNameChanging(string value)
{
if(value == null)
{
- // Use "value" rather than nameof(value)
- // prior to C# 6.0.
throw new ArgumentNullException(nameof(value));
}
if (value.Trim().Length == 0)
{
throw new ArgumentException(
"FirstName cannot be empty.",
- // Use "value" rather than nameof(value)
- // prior to C# 6.0.
nameof(value));
}

MODIFY
src/Chapter07/Chapter07.csproj
src/Chapter07/Chapter07.csproj
<ChapterNumber>07</ChapterNumber>
</PropertyGroup>
<PropertyGroup>
- <ExpectedWarnings>$(ExpectedWarnings)</ExpectedWarnings>
- <!--
- CS0108 hides inherited member warning where 'new' is advised.
- Listing the warning here causes it to be a warning rather than an error.
- -->
- <IgnoredWarnings>$(IgnoredWarnings),CS0108</IgnoredWarnings>
+ <!--CS0108 hides inherited member warning where 'new' is advised.-->
+ <ExpectedWarnings>$(ExpectedWarnings)CS0108,</ExpectedWarnings>
+ <!--Listing the warning here causes it to be a warning rather than an error.-->
+ <IgnoredWarnings>$(IgnoredWarnings)</IgnoredWarnings>
</PropertyGroup>
<Import Project="..\Chapter.props" />
+ <ItemGroup>
+ <Compile Remove="Table07.03.TypePatternMatchingWithIsOperator.cs" />
+ </ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\Program.cs">
<Link>Program.cs</Link>
</Compile>
</ItemGroup>
+ <ItemGroup>
+ <None Include="Table07.03.TypePatternMatchingWithIsOperator.cs" />
+ </ItemGroup>
</Project>

MODIFY
src/Chapter07/Listing07.11.OverrideVersusNewModifier.cs
src/Chapter07/Listing07.11.OverrideVersusNewModifier.cs
@@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_11
{
public class BaseClass
{
- public void DisplayName()
+ public static void DisplayName()
{
Console.WriteLine("BaseClass");
}
@@ -32,7 +32,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_11
public class SuperSubDerivedClass : SubDerivedClass
{
- public new void DisplayName()
+ public new static void DisplayName()
{
Console.WriteLine("SuperSubDerivedClass");
}
@@ -47,10 +47,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_11
DerivedClass derivedClass = superSubDerivedClass;
BaseClass baseClass = superSubDerivedClass;
- superSubDerivedClass.DisplayName();
+ SuperSubDerivedClass.DisplayName();
subDerivedClass.DisplayName();
derivedClass.DisplayName();
- baseClass.DisplayName();
+ BaseClass.DisplayName();
}
}
}

MODIFY
src/Chapter07/Storage.cs
src/Chapter07/Storage.cs
}
public bool IsInserted { get; set; }
- internal void Eject()
+ internal static void Eject()
{
Console.WriteLine("Ejecting the DVD...");
}
public UsbKey(long capacity) : base(capacity) { }
public bool IsPluggedIn { get; set; }
- internal void Unload()
+ internal static void Unload()
{
Console.WriteLine("Unloading the UsbKey...");
}

Warnings through Table06.03