Skip to content

Instantly share code, notes, and snippets.

@huanlin
Last active August 29, 2015 14:15
Show Gist options
  • Save huanlin/ace179c088b3fdf7578b to your computer and use it in GitHub Desktop.
Save huanlin/ace179c088b3fdf7578b to your computer and use it in GitHub Desktop.
Get property name at runtime.
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