wasSharpNET – Diff between revs 25 and 27

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 25 Rev 27
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // 3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6 // Based on Oguzhan KIRCALI & CDspace @ https://stackoverflow.com/questions/4272579/how-to-print-full-stack-trace-in-exception 6 // Based on Oguzhan KIRCALI & CDspace @ https://stackoverflow.com/questions/4272579/how-to-print-full-stack-trace-in-exception
7   7  
8 using System; 8 using System;
9 using System.Diagnostics; 9 using System.Diagnostics;
10 using System.Linq; 10 using System.Linq;
11 using System.Text; 11 using System.Text;
12   12  
13 namespace wasSharpNET.Diagnostics 13 namespace wasSharpNET.Diagnostics
14 { 14 {
15 public static class ExceptionExtensions 15 public static class ExceptionExtensions
16 { 16 {
17 public static string PrettyPrint(this Exception ex, int columns = 80) 17 public static string PrettyPrint(this Exception ex, int columns = 80)
18 { 18 {
19 if(ex == null) 19 if (ex == null)
20 return string.Empty; 20 return string.Empty;
21   21  
22 var st = new StackTrace(ex, true); 22 var st = new StackTrace(ex, true);
23 var frames = st.GetFrames(); 23 var frames = st.GetFrames();
24 if (frames == null) 24 if (frames == null)
25 return string.Empty; 25 return string.Empty;
26   26  
27 var sb = new StringBuilder(); 27 var sb = new StringBuilder();
28 sb.Append(Environment.NewLine); 28 sb.Append(Environment.NewLine);
29   29  
30 foreach (var frame in frames) 30 foreach (var frame in frames)
31 { 31 {
32 var fileName = frame?.GetFileName(); 32 var fileName = frame?.GetFileName();
33 if (string.IsNullOrEmpty(fileName)) 33 if (string.IsNullOrEmpty(fileName))
34 continue; 34 continue;
35   35  
36 sb.Append(Enumerable 36 sb.Append(Enumerable
37 .Repeat('-', columns) 37 .Repeat('-', columns)
38 .Concat(Environment.NewLine) 38 .Concat(Environment.NewLine)
39 .ToArray()); 39 .ToArray());
40 sb.Append("File: "); 40 sb.Append("File: ");
41 sb.Append(fileName); 41 sb.Append(fileName);
42 sb.Append(@" Method: "); 42 sb.Append(@" Method: ");
43 sb.Append(frame.GetMethod().Name); 43 sb.Append(frame.GetMethod().Name);
44 sb.Append(@" Line and Column : "); 44 sb.Append(@" Line and Column : ");
45 sb.Append(frame.GetFileLineNumber()); 45 sb.Append(frame.GetFileLineNumber());
46 sb.Append(@":"); 46 sb.Append(@":");
47 sb.Append(frame.GetFileColumnNumber()); 47 sb.Append(frame.GetFileColumnNumber());
48 sb.Append(Environment.NewLine); 48 sb.Append(Environment.NewLine);
49 } 49 }
50   50  
51 sb.Append(Enumerable 51 sb.Append(Enumerable
52 .Repeat('-', columns) 52 .Repeat('-', columns)
53 .Concat(Environment.NewLine) 53 .Concat(Environment.NewLine)
54 .ToArray()); 54 .ToArray());
55 sb.Append(ex); 55 sb.Append(ex);
56 sb.Append(Environment.NewLine); 56 sb.Append(Environment.NewLine);
57 sb.Append(Enumerable 57 sb.Append(Enumerable
58 .Repeat('-', columns) 58 .Repeat('-', columns)
59 .Concat(Environment.NewLine) 59 .Concat(Environment.NewLine)
60 .ToArray()); 60 .ToArray());
61   61  
62 return sb.ToString(); 62 return sb.ToString();
63 } 63 }
64 } 64 }
65 } 65 }
66   66  
-   67
Generated by GNU Enscript 1.6.5.90.
-   68  
-   69  
-   70