How do I configure a property of a static class in Spring.NET?

心已入冬 提交于 2019-12-02 01:13:31

Maybe a workaround can help.. This is not a static class but it works like one

namespace Nyan {
    public class Util{
        protected Util(){} //to avoid accidental instatiation

        public static string DATETIMEFORMAT = "HH:mm:ss";

        public static DateTime parseDate(string sDate)
        {
            return DateTime.ParseExact(sDate, DATETIMEFORMAT, CultureInfo.InvariantCulture);
        }
    }
}

<object id="Util" type="Nyan.Util, Nyan" singleton="true">
     <property name="DATETIMEFORMAT" value="HH-mm-ss" />
</object

and is used like any other static class:

protected void Page_Load(object sender, EventArgs e)
{
    DateTime sDate = Nyan.Util.parseDate("15-15-15"); //parsed with injected format
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!