Skip to content

Commit

Permalink
Merge pull request #150 from BenjaminMichaelis/v8.0
Browse files Browse the repository at this point in the history
Misc. Changes that are in manuscript
  • Loading branch information
BenjaminMichaelis authored Jan 19, 2021
2 parents 21fc8e5 + e3d9e89 commit c01b53e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
16 changes: 14 additions & 2 deletions src/Chapter10/Listing10.20.DefiningAFinalizer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_20
// Justification: Implementation is incomplete in the catch block.
#pragma warning disable CS0168 // Variable is declared but never used
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_20
{
using System;
using System.IO;

public class TemporaryFileStream
{
public TemporaryFileStream(string fileName)
{
File = new FileInfo(fileName);
// For a preferable solution use FileOptions.DeleteOnClose.
Stream = new FileStream(
File.FullName, FileMode.OpenOrCreate,
FileAccess.ReadWrite);
Expand All @@ -19,7 +23,15 @@ public TemporaryFileStream()
// Finalizer
~TemporaryFileStream()
{
Close();
try
{
Close();
}
catch (Exception exception)
{
// Write event to logs or UI
// ...
}
}

public FileStream Stream { get; }
Expand Down
14 changes: 8 additions & 6 deletions src/Chapter13/Listing13.25.ExamingingAnExpressionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Linq.Expressions;
using static System.Linq.Expressions.ExpressionType;

public class Program
{
Expand Down Expand Up @@ -45,12 +46,13 @@ private static void PrintSingle(
private static string NodeToString(Expression expression) =>
expression.NodeType switch
{
ExpressionType.Multiply => "*",
ExpressionType.Add => "+",
ExpressionType.Divide => "/",
ExpressionType.Subtract => "-",
ExpressionType.GreaterThan => ">",
ExpressionType.LessThan => "<",
// using static ExpressionType
Multiply => "*",
Add => "+",
Divide => "/",
Subtract => "-",
GreaterThan => ">",
LessThan => "<",
_ => expression.ToString() +
" (" + expression.NodeType.ToString() + ")",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public float CurrentTemperature
List<Exception> exceptionCollection =
new List<Exception>();
foreach(
Action<float> handler in
Delegate handler in
onTemperatureChange.GetInvocationList())
{
try
{
handler(value);
((Action<float>)handler)(value);
}
catch(Exception exception)
{
Expand Down

0 comments on commit c01b53e

Please sign in to comment.