mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-03-18 10:24:40 +01:00
Initial commit
This commit is contained in:
parent
bf63cf7d4b
commit
965e874957
17
vs4win/Chapter04/Instrumenting/Program.Methods.cs
Normal file
17
vs4win/Chapter04/Instrumenting/Program.Methods.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System.Diagnostics; // Trace
|
||||
using System.Runtime.CompilerServices; // [Caller...] attributes
|
||||
|
||||
partial class Program
|
||||
{
|
||||
static void LogSourceDetails(
|
||||
bool condition,
|
||||
[CallerMemberName] string member = "",
|
||||
[CallerFilePath] string filepath = "",
|
||||
[CallerLineNumber] int line = 0,
|
||||
[CallerArgumentExpression(nameof(condition))] string expression = "")
|
||||
{
|
||||
Trace.WriteLine(string.Format(
|
||||
"[{0}]\n {1} on line {2}. Expression: {3}",
|
||||
filepath, member, line, expression));
|
||||
}
|
||||
}
|
||||
|
|
@ -40,4 +40,7 @@ Trace.WriteLineIf(ts.TraceWarning, "Trace warning");
|
|||
Trace.WriteLineIf(ts.TraceInfo, "Trace information");
|
||||
Trace.WriteLineIf(ts.TraceVerbose, "Trace verbose");
|
||||
|
||||
Console.ReadLine();
|
||||
int unitsInStock = 12;
|
||||
LogSourceDetails(unitsInStock > 10);
|
||||
|
||||
Console.ReadLine();
|
||||
|
|
|
|||
17
vscode/Chapter04/Instrumenting/Program.Methods.cs
Normal file
17
vscode/Chapter04/Instrumenting/Program.Methods.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System.Diagnostics; // Trace
|
||||
using System.Runtime.CompilerServices; // [Caller...] attributes
|
||||
|
||||
partial class Program
|
||||
{
|
||||
static void LogSourceDetails(
|
||||
bool condition,
|
||||
[CallerMemberName] string member = "",
|
||||
[CallerFilePath] string filepath = "",
|
||||
[CallerLineNumber] int line = 0,
|
||||
[CallerArgumentExpression(nameof(condition))] string expression = "")
|
||||
{
|
||||
Trace.WriteLine(string.Format(
|
||||
"[{0}]\n {1} on line {2}. Expression: {3}",
|
||||
filepath, member, line, expression));
|
||||
}
|
||||
}
|
||||
|
|
@ -40,4 +40,7 @@ Trace.WriteLineIf(ts.TraceWarning, "Trace warning");
|
|||
Trace.WriteLineIf(ts.TraceInfo, "Trace information");
|
||||
Trace.WriteLineIf(ts.TraceVerbose, "Trace verbose");
|
||||
|
||||
Console.ReadLine();
|
||||
int unitsInStock = 12;
|
||||
LogSourceDetails(unitsInStock > 10);
|
||||
|
||||
Console.ReadLine();
|
||||
|
|
|
|||
Loading…
Reference in a new issue