首页 > 代码库 > 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类型的数据)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。