Rebase on v9.0 Branch
MODIFY
src/Chapter06/Listing06.35A.RequiredProperties.cs
src/Chapter06/Listing06.35A.RequiredProperties.cs
@@ -58,7 +58,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_35A
Title= "Harold and the Purple Crayon"
};
#region EXCLUDE
- #pragma warning enable IDE0059 // Unnecessary assignment of a value
+ #pragma warning restore IDE0059 // Unnecessary assignment of a value
#endregion EXCLUDE
}
}

MODIFY
src/Chapter09.Tests/Listing09.02.ReadOnlyMembers.Tests.cs
src/Chapter09.Tests/Listing09.02.ReadOnlyMembers.Tests.cs
@@ -11,7 +11,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_02.Tests
public class MyTestClass
{
[TestMethod]
- public async Task ReadOnlyMethod_ModifyObject_ErrorReported()
+ public void ReadOnlyMethod_ModifyObject_ErrorReported()
{
string thingCode = @"
public struct Thing
@@ -35,9 +35,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_02.Tests
}
}";
- await CompilerAssert.ExpectErrorsAsync(thingCode,
- new CompileError("CS1604", "Cannot assign to 'Number' because it is read-only")
- );
+ CompilerAssert.ExpectErrorsAsync(thingCode,
+ new CompileError("CS1604", "Cannot assign to 'Number' because it is read-only"));
}
}
}
\ No newline at end of file

MODIFY
src/Shared/CompilerAssert.cs
src/Shared/CompilerAssert.cs
@@ -10,7 +10,9 @@ using Microsoft.CodeAnalysis.Text;
namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
{
- public readonly struct CompileError
+
+
+ readonly public struct CompileError
{
public static Dictionary<string, string?> CompilerErrorMessages { get; } = new Dictionary<string, string?>()
{
@@ -80,8 +82,15 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
CompileError lhs, CompileError rhs) =>
!lhs.Equals(rhs);
}
- public static class CompilerAssert
+ static public class CompilerAssert
{
+
+ private static readonly CSharpCompilationOptions DefaultCompilationOptions =
+ new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
+ .WithOverflowChecks(true).WithOptimizationLevel(OptimizationLevel.Release);
+ //.WithUsings(DefaultNamespaces);
+
+
public static async Task Compile2Async(
string fileName,
string[] errorIds,
@@ -170,7 +179,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
return ExpectErrorsAsync(sourceCode, diagnostics);
}
- static public CompileError[] ExpectErrorsAsync(
+ public static CompileError[] ExpectErrorsAsync(
string sourceCode, params CompileError[] diagnostics)
{
ArgumentNullException.ThrowIfNull(diagnostics);
@@ -181,7 +190,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
for (int i = 0; i < Math.Min(actualCompileErrors.Length, diagnostics.Length); i++)
{
// Compare Id's first as that is more meaningful.
- Assert.AreEqual<(string Id, string Message)>((Id:diagnostics[i].Id, Message:diagnostics[i].Message), (Id: actualCompileErrors[i].Id, Message: actualCompileErrors[i].Message));
+ Assert.AreEqual<(string Id, string Message)>(
+ (diagnostics[i].Id, diagnostics[i].Message), (actualCompileErrors[i].Id, actualCompileErrors[i].Message));
//$"The expected Ids do not match for item {i}: " +
//$"{diagnostics[i].Id}: {diagnostics[i].Message} <> {actualCompileErrors[i].Id}: {actualCompileErrors[i].Message}");
}
@@ -193,6 +203,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
Assert.Fail("The expected compilation errors did not occur.");
return null!; // This code will never execute due to the Fail line above.
}
+
public static async Task<CompileError[]> CompileAsyncOld(
string sourceCode)
{

Rebase on v9.0 Branch