Last active
August 29, 2015 14:15
-
-
Save huanlin/ace179c088b3fdf7578b to your computer and use it in GitHub Desktop.
Get property name at runtime.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Runtime.CompilerServices; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var customer = new Customer(); | |
string s = customer.FullName; | |
} | |
} | |
class Customer | |
{ | |
private string _fullName; | |
public string FullName | |
{ | |
get | |
{ | |
ObjectPropertyList.Add(this); | |
return _fullName; | |
} | |
} | |
} | |
static class ObjectPropertyList | |
{ | |
public static void Add(object obj, [CallerMemberName] string propertyName="") | |
{ | |
Console.WriteLine("Added {0}.{1} to list.", obj.GetType().Name, propertyName); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment