开发者

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

How do I configure a static class via Spring .NET?

Consider the following cl开发者_如何转开发ass:

static class Abc
{
   public Interface xyz
   {
       get;
       set;
   }

   public void Show()
   {
      xyz.show();
   }
}


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜