Shortcut To Creating Properties in C-Sharp – Revisited
Published: Sep 21, 2011 17:57:41
Physical Link: Shortcut To Creating Properties in C-Sharp – Revisited
Based on my earlier an post, a I had a question about my technique and if there was a benefit, or could you use MethodBase.GetCurrentMethod().Name. Truthfully I did not know the answer until I tried it. I found this new way works, but I also find it is a little tougher to look at style-wise. You need to use stack frames if you nest the routine like I had in my original post.
public class ErrorLogRecord
{
public Hashtable _hsh = new Hashtable();
public DateTime DateOfOccurance
{
get { return (DateTime?)_hsh[MethodBase.GetCurrentMethod().Name.Replace("set_", "").Replace("get_", "")] ?? DateTime.Now; }
set { _hsh[MethodBase.GetCurrentMethod().Name.Replace("set_", "").Replace("get_", "")] = value; }
}
public String ErrorText
{
get { return (String)_hsh[MethodBase.GetCurrentMethod().Name.Replace("set_", "").Replace("get_", "")]; }
set { _hsh[MethodBase.GetCurrentMethod().Name.Replace("set_", "").Replace("get_", "")] = value; }
}
}
Original Referenec Shortcut To Creating Properties in C-Sharp
The post Shortcut To Creating Properties in C-Sharp – Revisited appeared first on LDNDeveloper.
Author: Andrew PallantCategories: C#, Deployment, Developer, DotNet, How To, Ideas