Caller information gives information about the caller of any function. This concept was introduced in C# 5.0 . In C# 5.0 the caller info feature has introduced and using this feature we can easily get information about caller function.
These three types of attributes that are used in tracking information..
- CallerFilePath: Sets the information about caller's source code file.
- CallerLineNumber: Sets the information about caller's line number.
- CallerMemberName: Sets the information about caller member name.
Let us take an example:
- using System;
- using System.Runtime.CompilerServices;
- namespace ConsApp
- {
- class Program
- {
- public void Call(string text, [CallerFilePath] string File_name = "",
- [CallerLineNumber] int Line = 0,
- [CallerMemberName] string member_name = "")
- {
- Console.WriteLine(text);
- Console.WriteLine(File_name);
- Console.WriteLine(Line);
- Console.WriteLine(member_name);
- }
- static void Main(string[] args)
- {
- Program Obj = new Program();
- Obj.Call("This is Caller Method");
- Console.ReadLine();
- }
- }
- }
Output
Before the tracking information used the StactTrack to find out the tracking information of a method that was very complicated to handle.