Remove CompileErrorLines from listing Output
Fixes Intellitect/EssentialCSharpManuscript#601
MODIFY
src/Chapter03/Listing03.02.DereferencingAnUnassignedVariable.cs
src/Chapter03/Listing03.02.DereferencingAnUnassignedVariable.cs
@@ -6,12 +6,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_02
#nullable enable
public static void Main()
{
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
string? text;
// ...
// Compile Error: Use of unassigned local variable 'text'
System.Console.WriteLine(text.Length);
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
}
#endregion INCLUDE
}

MODIFY
src/Chapter06/Listing06.15.UsingThePrivateAccessModifier.cs
src/Chapter06/Listing06.15.UsingThePrivateAccessModifier.cs
@@ -55,14 +55,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_15
// ...
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
#region HIGHLIGHT
// ERROR: Password is private, so it cannot be
// accessed from outside the class
Console.WriteLine(
"Password = {0}", employee.Password);
#endregion HIGHLIGHT
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
}
// ...
}

MODIFY
src/Chapter06/Listing06.21.DefiningReadOnlyProperties.cs
src/Chapter06/Listing06.21.DefiningReadOnlyProperties.cs
@@ -11,13 +11,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_21
Employee employee1 = new();
employee1.Initialize(42);
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
#region HIGHLIGHT
// ERROR: Property or indexer 'Employee.Id'
// cannot be assigned to; it is read-only
employee1.Id = "490";
#endregion HIGHLIGHT
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
}
}

MODIFY
src/Chapter06/Listing06.23.PlacingAccessModifiersOnSetters.cs
src/Chapter06/Listing06.23.PlacingAccessModifiersOnSetters.cs
@@ -10,14 +10,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_23
{
Employee employee1 = new();
employee1.Initialize(42);
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
#region HIGHLIGHT
// ERROR: The property or indexer 'Employee.Id'
// cannot be used in this context because the set
// accessor is inaccessible
employee1.Id = "490";
#endregion HIGHLIGHT
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
}
}

MODIFY
src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs
src/Chapter06/Listing06.28.DefaultConstructorNoLongerAvailable.cs
@@ -12,13 +12,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_28
{
Employee employee;
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
#region HIGHLIGHT
// ERROR: No overload because method 'Employee'
// takes '0' arguments
employee = new Employee();
#endregion HIGHLIGHT
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
// ...
}

MODIFY
src/Chapter06/Listing06.31.InitOnlySetters.cs
src/Chapter06/Listing06.31.InitOnlySetters.cs
@@ -39,13 +39,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_31
};
#endregion HIGHLIGHT
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
#region HIGHLIGHT
// ERROR: Property or indexer 'Employee.Salary'
// cannot be assigned after initialization completes.
employee.Salary = "Enough";
#endregion HIGHLIGHT
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
}
}
#endregion INCLUDE

MODIFY
src/Chapter06/Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.cs
src/Chapter06/Listing06.38.SpecifyingRequiredMembersWithinTheObjectInitializer.cs
#if NET7_0_OR_GREATER
-#if COMPILEERROR
+#if COMPILEERROR // EXCLUDE
using AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_37;
-#endif // COMPILEERROR
+#endif // COMPILEERROR // EXCLUDE
using System.Runtime.CompilerServices;
@@ -12,7 +12,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38
{
public static void Main()
{
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
#region INCLUDE
// Error CS9035:
// Required member 'Book.Isbn' must be set in the object
@@ -21,7 +21,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_38
// ...
#endregion INCLUDE
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
}
}
}

MODIFY
src/Chapter06/Listing06.53.DeclaringAFieldAsReadonly.cs
src/Chapter06/Listing06.53.DeclaringAFieldAsReadonly.cs
@@ -18,12 +18,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_53
get { return _Id; }
}
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
// Error: A readonly field cannot be assigned to (except
// in a constructor or a variable initializer)
public void SetId(int id) =>
_Id = id;
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
// ...
}

MODIFY
src/Chapter07/Listing07.06.PrivateMembersAreNotInherited.cs
src/Chapter07/Listing07.06.PrivateMembersAreNotInherited.cs
@@ -35,11 +35,11 @@ public class Program
{
Contact contact = new Contact();
#region HIGHLIGHT
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
// ERROR: 'PdaItem._Name' is inaccessible
// due to its protection level
contact._Name = "Inigo Montoya";
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
#endregion HIGHLIGHT
}
}

MODIFY
src/Chapter07/Listing07.07.ProtectedMembersAreAccessibleOnlyFromDerivedClasses.cs
src/Chapter07/Listing07.07.ProtectedMembersAreAccessibleOnlyFromDerivedClasses.cs
@@ -33,14 +33,14 @@ public class Contact : PdaItem
=> new(contact.ObjectKey);
#endregion HIGHLIGHT
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
static public Contact Copy(PdaItem pdaItem) =>
#region HIGHLIGHT
// ERROR: Cannot access protected member PdaItem.ObjectKey.
// Use ((Contact)pdaItem).ObjectKey instead.
new(pdaItem.ObjectKey);
#endregion HIGHLIGHT
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
}
public class Program
@@ -50,10 +50,10 @@ public class Program
Contact contact = new(Guid.NewGuid());
#region HIGHLIGHT
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
// ERROR: 'PdaItem.ObjectKey' is inaccessible
Console.WriteLine(contact.ObjectKey);
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
#endregion HIGHLIGHT
}
}

MODIFY
src/Chapter07/Listing07.08.PreventingDerivationWithSealedClasses.cs
src/Chapter07/Listing07.08.PreventingDerivationWithSealedClasses.cs
@@ -6,12 +6,12 @@ public sealed class CommandLineParser
// ...
}
-#if COMPILEERROR
+#if COMPILEERROR // EXCLUDE
// ERROR: Sealed classes cannot be derived from
public sealed class DerivedCommandLineParser
: CommandLineParser
{
// ...
}
-#endif // COMPILEERROR
+#endif // COMPILEERROR // EXCLUDE
#endregion INCLUDE

MODIFY
src/Chapter07/Listing07.15.DefiningAnAbstractClass.cs
src/Chapter07/Listing07.15.DefiningAnAbstractClass.cs
@@ -21,10 +21,10 @@ public class Program
public static void Main()
{
- #if COMPILEERROR
+ #if COMPILEERROR // EXCLUDE
// ERROR: Cannot create an instance of the abstract class
PdaItem item = new("Inigo Montoya");
- #endif // COMPILEERROR
+ #endif // COMPILEERROR // EXCLUDE
}
}
#endregion INCLUDE

Remove CompileErrorLines from listing Output  (#423)

Fixes Intellitect/EssentialCSharpManuscript#601