LDNDeveloper

Andrew Pallant

     Senior IT Executive 


Donate To Support My Blog Donate if this post helped you. Coffee money is always welcomed!




Shortcut To Creating Properties in C-Sharp – Revisited

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:
Categories: C#, Deployment, Developer, DotNet, How To, Ideas


©2024 LdnDeveloper