Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. Changes that are in manuscript #150

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update Manuscript on this?

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