CallerInfo Attribute in C#

There are three types of CallerInfo attribute, such as CallerMemberName, CallerFilePath, and CallerLineNumber. These attributes are helpful in Debugging code.

The System.Runtime.CompilerServices namespace is used for these attributes.


The following class has three methods which are having CallerInfo attributes, such as CallerMemberName, CallerFilePath, and CallerLineNumber. All these methods return a string message. The optional parameter is used, however, if we call with no parameters the CompilerSevice would consider the current file as file and current method as method and the line number as well.


Let’s see it’s in Debug’s output. Add System.Diagnostics namespace to use Debug class and it’s methods.


As you see in the following debug window, all the three Employee class methods are called. Also all these methods are having no parameters, and the output says it all. The method it’s using, the file it’s using and the line number from where it’s called.


All in all, a good attribute for extensive debugging knowing places from which piece of code, method, or even line number are being used.


Hope this post was useful.

Thanks for reading. Like Method Of Tried in Facebook.