首页 > 代码库 > Spring对象实例化,获取配置文件中的值(property为IDictionary类型的数据)

Spring对象实例化,获取配置文件中的值(property为IDictionary类型的数据)

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Text;namespace WeiXin.Core{    public static class JobBase    {        private static IDictionary<string, string> ParNameDictionary;        private static IDictionary<string, string> FunctionDictionary;        private static IDictionary<string, string> IplatformDictionary;        /// <summary>        /// 从配置文件中获取ParamInfo对应的值        /// </summary>        /// <param name="parName"></param>        /// <returns></returns>        public static string GetConfParamValue(ParamEnum parName)        {            if (ParNameDictionary==null)            {                ParNameDictionary=SpringContainer.GetObject<ParamList>("SystemList").ParamInfoList;            }            return ParNameDictionary[parName.ToString()];        }        public static string GetConfFunctionValue(FunctionEnum functionName)        {            if (FunctionDictionary==null)            {                FunctionDictionary=SpringContainer.GetObject<ParamList>("SystemList").SendXmlPathList;            }            return FunctionDictionary[functionName.ToString()];        }        public static string GetConfApiValue(IplatformEnum platformName)        {            if (IplatformDictionary==null)            {                IplatformDictionary = SpringContainer.GetObject<ParamList>("SystemList").IplatformList;            }            return IplatformDictionary[platformName.ToString()];        }        public static string Bytes(string str)        {            string newStr = string.Empty;            int i = Encoding.GetEncoding("GB2312").GetByteCount(str);            if (i>30)            {                foreach (char charTemp in str)                {                    newStr += charTemp.ToString();                    if (Encoding.GetEncoding("GB2312").GetByteCount(newStr)==30)                    {                        newStr += "...";                        break;                    }                }                return newStr;                            }            return str;        }    }}
<?xml version="1.0" encoding="utf-8"?><objects xmlns="http://www.springframework.net"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"           xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">  <object id="SystemList" type="YTO.WeiXin.Core.ParamList,YTO.WeiXin.Core">    <property name="ParamInfoList">      <dictionary key-type="string" value-type="string">        <entry key="AppID" value="wxf96dbe9e4723b1b8"/>        <entry key="AppSecret" value="1d010913658421023c6ebc403580e8ea"/>             </dictionary>    </property>    <property name="IplatformList">      <dictionary key-type="string" value-type="string">        <entry key="TokenXML" value="C:\Data\qiyun\XML\Token.xml"/>            </dictionary>    </property>  </object></objects>

 

Spring对象实例化,获取配置文件中的值(property为IDictionary类型的数据)