23
Sep
2012
Sep
2012
Caller Info Attributes in C# 5.0
<!-- Adsense Code Here
- [CallerMemberName] – It applies the caller’s member name
- [CallerFilePath] - It applies the path to the caller’s source code file
- [CallerLineNumber]- It applies the line number in the caller’s source code file
1: using System;
2: using System.Runtime.CompilerServices;
3: class Program
4: {
5: static void Main()
6: {
7: Demo();
8: }
9: static void Demo (
10: [CallerMemberName] string memberName = null,
11: [CallerFilePath] string filePath = null,
12: [CallerLineNumber] int lineNumber = 0)
13: {
14: Console.WriteLine (memberName);
15: Console.WriteLine (filePath);
16: Console.WriteLine (lineNumber);
17: }
18: }
Main
C:\Projects\Program.cs (Assuming your project is located in this path)
16
Caller Info attributes are useful for writing logging functions and for implementing change notification patterns. The following method can be called from property’s set accessor
1: void RaisePropertyChanged( [CallMemberName] string propertyName = null)
2: {
3:
4: }
No comments:
Post a Comment