You are currently offline, waiting for your internet to reconnect

How-To: User Caller Info Attributes

About Author:
This article is provided by Sanchez Roman Canlas, a Senior Developer Consultant at US Technologies Global and a core member of the Phillipine Windows Developer Group
Caller Info Attributes
You can tag optional parameters in your method using one of the 3 caller info attributes and use that information for logging purposes
  • [CallerMemberInfoName]
  • [CallerFilePath]
  • [CallerLineNumber]
These attributes tells the compiler to deliver the information retrieved from the caller's source code into the parameter's default value

Example
using System;
using System.Runtime.CompilerServices;

namespace CallerInfoAttributesDemo
{
class Program
{
static void Main(string[] args)
{
LogCallerInfo();
}

private static void LogCallerInfo
(
[CallerMemberName] string callersMemberName = null,
[CallerFilePath] string callersSourceCodePath = null,
[CallerLineNumber] string callersSourceCodeLineNumber = 0
)
{
Console.WriteLine(callersMemberName); // displays the caller's member name
Console.WriteLine(callersSourceCodePath); // displays the caller's source code file
Console.WriteLine(callersSourceCodeLineNumber); // displays the line number in the caller's source code
Console.ReadLine();
}
}
}
Output
Main
C:\Test\Program.cs
10

Community Solutions Content Disclaimer

MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.
Properties

Article ID: 2778991 - Last Review: 10/31/2012 02:22:00 - Revision: 2.0

Microsoft Visual C# 2010 Express

  • KB2778991
Feedback
>iv ng-repeat="language in languagesListForLargeScreens track by $index" class="col-sm-6 col-xs-24 ng-scope">
://c1.microsoft.com/c.gif?DI=4050&did=1&t="> var varCustomerTracking = 1; var Route = "76500"; var Ctrl = ""; document.write(" ment('meta');m.name='ms.dqp0';m.content='true';document.getElementsByTagName('head')[0].appendChild(m);" onload="var m=document.createElement('meta');m.name='ms.dqp0';m.content='false';document.getElementsByTagName('head')[0].appendChild(m);" src="http://c1.microsoft.com/c.gif?">