如何配置一个静态类Spring.NET的属性?静态、属性、Spring、NET

2023-09-03 06:27:06 作者:再牛的名字也抵不过备注

如何配置通过Spring .NET静态类?

考虑下面的类:

 静态ABC类
{
   公共接口XYZ
   {
       得到;
       组;
   }

   公共无效展()
   {
      xyz.s​​how();
   }
}
 

解决方案

也许一种变通方法可以帮助.. 这不是一个静态类,但它就像一个

 命名空间的吴年{
    公共类的Util {
        受保护的Util(){} //避免意外instatiation

        公共静态字符串DATETIMEFORMAT =HH:MM:SS;

        公共静态的DateTime parseDate(字符串SDATE)
        {
            返回DateTime.ParseExact(SDATE,DATETIMEFORMAT,CultureInfo.InvariantCulture);
        }
    }
}

<对象ID =的UtilTYPE =Nyan.Util,吴年单身=真正的>
     <属性名=DATETIMEFORMAT值=HH-MM-SS/>
< /对象
 

和使用像任何其他静态类:

 保护无效的Page_Load(对象发件人,EventArgs的)
{
    日期时间SDATE = Nyan.Util.parseDate(15-15-15); //解析与注入的格式
}
 
Spring.Net入门学习 基础配置

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

Consider the following class:

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
}