-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from cjvandyk/6.11.800
6.11.800
- Loading branch information
Showing
4 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/// <summary> | ||
/// Author: Cornelius J. van Dyk blog.cjvandyk.com @cjvandyk | ||
/// This code is provided under GNU GPL 3.0 and is a copyrighted work of the | ||
/// author and contributors. Please see: | ||
/// https://github.com/cjvandyk/Extensions/blob/main/LICENSE | ||
/// </summary> | ||
|
||
using System; | ||
using static Extensions.Core; | ||
|
||
namespace Extensions | ||
{ | ||
/// <summary> | ||
/// Extensions for the System.Diagnostics.StackTrace class. | ||
/// </summary> | ||
[Serializable] | ||
public static partial class StackTraceExtensions | ||
{ | ||
#region Parentage | ||
/// <summary> | ||
/// A method to return the calling method's name. Two other methods | ||
/// exist in the Parentage group i.e. GrandParent() and | ||
/// GreatGrandParent(). If Generations of callers further back are | ||
/// needed, this method can be called with the specific number of | ||
/// generations to traverse up the calling tree. If the value of the | ||
/// generations exceed the number of callers in the StackTrace calling | ||
/// tree, then null will be returned. | ||
/// </summary> | ||
/// <param name="stackTrace">This instance of the StackTrace.</param> | ||
/// <param name="generations">The number of generations to traverse | ||
/// back up the stack. Default is 1.</param> | ||
/// <returns>The name of the calling method x generations ago.</returns> | ||
public static string Parent( | ||
this System.Diagnostics.StackTrace stackTrace, | ||
int generations = 1) | ||
{ | ||
ValidateNoNulls(stackTrace, generations); | ||
try | ||
{ | ||
return stackTrace.GetFrame(generations).GetMethod().Name; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Err(ex.ToString()); | ||
return null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// A method to return the calling method's | ||
/// calling method's name. | ||
/// </summary> | ||
/// <returns>The name of the calling method 2 generations ago.</returns> | ||
public static string GrandParent() | ||
{ | ||
return Parent(new System.Diagnostics.StackTrace(), 2); | ||
} | ||
|
||
/// <summary> | ||
/// A method to return the calling method's | ||
/// calling method's | ||
/// calling method's name. | ||
/// </summary> | ||
/// <returns>The name of the calling method 3 generations ago.</returns> | ||
public static string GreatGrandParent() | ||
{ | ||
return Parent(new System.Diagnostics.StackTrace(), 3); | ||
} | ||
#endregion Parentage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters