Getting Caller Information using Caller Info attributes is initially introduced with .NET Framework 4.5. It can be real handy if you want to write a module for tracing, debugging etc.
Following are the Caller Info Attributes which are defined in System.Runtime.CompilerServices namespace.
- Method or property name of the caller.
- Full path of the source file that contains the caller. This is the file path at compile time.
- Line number in the source file at which the method is called.
Let’s see a very simple example.
Please note the optional parameters which are marked with Caller Info Attributes in the TraceMessage method.
This will print the following output.
Please check the following post to get to know about a scenario where Caller Information can be used very effectively.INotifyPropertyChanged Without Hardcoding the Property Name
Download the sample from my SkyDrive.