public static string GetMethodName()
{
var method = new StackFrame(1).GetMethod(); // 这里忽略1层堆栈,也就忽略了当前方法GetMethodName,这样拿到的就正好是外部调用GetMethodName的方法信息
var property = (
from p in method.DeclaringType.GetProperties(
BindingFlags.Instance |
BindingFlags.Static |
BindingFlags.Public |
BindingFlags.NonPublic)
where p.GetGetMethod(true) == method || p.GetSetMethod(true) == method
select p).FirstOrDefault();
return property == null ? method.Name : property.Name;
}
2013-1-25
publiceventPropertyChangedEventHandlerPropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
privatevoidNotifyPropertyChanged([CallerMemberName]stringpropertyName ="")
{
if(PropertyChanged!=null)
{
PropertyChanged(this,newPropertyChangedEventArgs(propertyName));
}
}
2013-1-26