Created
April 30, 2024 19:04
-
-
Save CamelCaseName/a8cc181af0a3986976c181394a13f831 to your computer and use it in GitHub Desktop.
simple wrapper to get information on where a call was made from
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
using System; | |
namespace Freecam | |
{ | |
public static class CallWrapper | |
{ | |
public static void Wrap(Action a, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
a.Invoke(); | |
} | |
public static TResult Wrap<TResult>(Func<TResult> a, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
return a.Invoke(); | |
} | |
public static TResult Wrap<TResult, T>(Func<T, TResult> a, T value0, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
return a.Invoke(value0); | |
} | |
public static TResult Wrap<TResult, T, X>(Func<T, X, TResult> a, T value0, X value1, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
return a.Invoke(value0, value1); | |
} | |
public static TResult Wrap<TResult, T, X, Y>(Func<T, X, Y, TResult> a, T value0, X value1, Y value2, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
return a.Invoke(value0, value1, value2); | |
} | |
public static TResult Wrap<TResult, T, X, Y, Z>(Func<T, X, Y, Z, TResult> a, T value0, X value1, Y value2, Z value3, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
return a.Invoke(value0, value1, value2, value3); | |
} | |
public static void Wrap<T>(Action<T> a, T value0, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
a.Invoke(value0); | |
} | |
public static void Wrap<T, X>(Action<T, X> a, T value0, X value1, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
a.Invoke(value0, value1); | |
} | |
public static void Wrap<T, X, Y>(Action<T, X, Y> a, T value0, X value1, Y value2, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
a.Invoke(value0, value1, value2); | |
} | |
public static void Wrap<T, X, Y, Z>(Action<T, X, Y, Z> a, T value0, X value1, Y value2, Z value3, [System.Runtime.CompilerServices.CallerMemberName] string caller = "", [System.Runtime.CompilerServices.CallerLineNumber] int line = 0) | |
{ | |
Console.WriteLine($"{a.Method.Name} called from {caller}:{line}"); | |
a.Invoke(value0, value1, value2, value3); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment