如何配置一个静态类Spring.NET的属性? [英] How do I configure a property of a static class in Spring.NET?

查看:179
本文介绍了如何配置一个静态类Spring.NET的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置通过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); //解析与注入的格式
}
 

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
}

这篇关于如何配置一个静态类Spring.NET的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆