Switched "is object" to "is not null"
MODIFY
src/Chapter05/Listing05.22.CountingLinesUsingOverloading.cs
src/Chapter05/Listing05.22.CountingLinesUsingOverloading.cs
@@ -76,7 +76,7 @@ public static class LineCounter
new FileStream(file, FileMode.Open);
StreamReader reader = new StreamReader(stream);
line = reader.ReadLine();
- while(line is object)
+ while(line is not null)
{
if(line.Trim() != "")
{

MODIFY
src/Chapter05/Listing05.23.MethodsWithOptionalParameters.cs
src/Chapter05/Listing05.23.MethodsWithOptionalParameters.cs
@@ -70,7 +70,7 @@ public static class LineCounter
new FileStream(file, FileMode.Open);
StreamReader reader = new StreamReader(stream);
line = reader.ReadLine();
- while (line is object)
+ while (line is not null)
{
if (line.Trim() != "")
{

MODIFY
src/Chapter06.Tests/Listing06.37.UsingTheMaybeNullAttribute.Tests.cs
src/Chapter06.Tests/Listing06.37.UsingTheMaybeNullAttribute.Tests.cs
@@ -8,15 +8,15 @@ public class ProgramTests
[TestMethod]
public void GetObject_CollectionWithItem_ReturnItem()
{
- Assert.IsNull(NullabilityAttributesExamined.GetObject(
- new string[] { "item" }, item => item is object));
+ Assert.IsNotNull(NullabilityAttributesExamined.GetObject(
+ new string[] { "item" }, item => item is not null));
}
[TestMethod]
public void GetObject_GivenEmptyCollection_ReturnNull()
{
Assert.IsNull(NullabilityAttributesExamined.GetObject(
- System.Array.Empty<string>(), item => item is object));
+ System.Array.Empty<string>(), item => item is not null));
}
[TestMethod]

MODIFY
src/Chapter06/Listing06.36.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs
src/Chapter06/Listing06.36.UsingNotNullWhenAndNotNullIfNotNullAttributes.cs
@@ -17,7 +17,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_36
// ...
'9' => "nine",
_ => null
- }) is string;
+ }) is not null;
[return: NotNullIfNotNull("text")]
static public string? TryGetDigitsAsText(string? text)

MODIFY
src/Chapter10/Listing10.06.ImplementingTheEqualsAndNotEqualsOperators.cs
src/Chapter10/Listing10.06.ImplementingTheEqualsAndNotEqualsOperators.cs
// }
// STEP 1: Check for null
- return ((obj is object)
+ return ((obj is not null)
// STEP 5: Compare identifying fields for equality.
&& (ProductSeries == obj.ProductSeries) &&
(Model == obj.Model) &&

MODIFY
src/Chapter10/Listing10.19.WeakReferences.cs
src/Chapter10/Listing10.19.WeakReferences.cs
{
byte[]? data = (byte[]?)Data.Target;
- if (data is object)
+ if (data is not null)
{
return data;
}

MODIFY
src/Shared/Program.cs
src/Shared/Program.cs
@@ -163,7 +163,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
{
return "<null>";
}
- else if (method.GetCustomAttribute(typeof(AsyncIteratorStateMachineAttribute), false) is object)
+ else if (method.GetCustomAttribute(typeof(AsyncIteratorStateMachineAttribute), false) is not null)
{
return result switch
{
@@ -173,7 +173,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
_ => throw new NotImplementedException($"This {nameof(IAsyncEnumerable<string>)} type parameter is not implemented."),
};
}
- else if (method.GetCustomAttribute(typeof(AsyncStateMachineAttribute), false) is object)
+ else if (method.GetCustomAttribute(typeof(AsyncStateMachineAttribute), false) is not null)
{
switch (result)
{

Switched "is object" to "is not null"