by
79 6
0
4
47
0
Tagged
Specified
Tuned
OpenSource
Created
Modified Sep 25, 2019
InputName0testClass
InputName1message
InputName2lineNumber
InputName3caller
InputType0object
InputType1string
InputType2int
InputType3string
Languagecsharp
LicenseMIT_X11
MethodNameFail
OutputTypevoid

Find line number and member name via reflection

This method allows to know the line number and the method name of the caller
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/4361201/Find-line-number-and-member-name-via-ref?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System.Reflection; using System.Runtime.CompilerServices; public static void Fail(this object testClass, string message = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null) { throw new FailTestException(string.Format("{0}.{1} failed at line {2} {3}", testClass.GetType().FullName, caller, lineNumber, message)); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus