[XML] Resource帮助类
/// <summary>
/// 类说明:Resources
/// 编 码 人:苏飞
/// 联系方式:361983679
/// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
/// </summary> using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization; namespace DotNet.Utilities
{
/// <summary>
/// BUResourceManager
/// 资源管理器
/// </author>
/// </summary>
[XmlRoot("resources")]
public class Resources
{
private SortedList<String, String> indexs = new SortedList<String, String>(); [XmlElement("language")]
public string language = string.Empty;
[XmlElement("displayName")]
public string displayName = string.Empty;
[XmlElement("version")]
public string version = string.Empty;
[XmlElement("author")]
public string author = string.Empty;
[XmlElement("description")]
public string description = string.Empty;
[XmlElement("items", typeof(Items))]
public Items items; public void createIndex()
{
indexs.Clear();
if (items == null)
{
return;
}
indexs = new SortedList<String, String>(items.items.Length);
for (int i = ; i < items.items.Length; i++)
{
#if DEBUG
try
{
[i] indexs.Add(items.items.key, items.items.value);
}
catch
{
throw (new Exception(items.items.key + items.items.value));
}
#else
indexs.Add(items.items.key, items.items.value);
#endif
}
} public string Get(string key)
{
if (!indexs.ContainsKey(key))
{
return string.Empty;
}
return indexs[key];
} /// <summary>
/// JiRiGaLa 2007.05.02
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool Set(string key, string value)
{
if (!indexs.ContainsKey(key))
{
return false;
}
indexs[key] = value;
for (int i = ; i < items.items.Length; i++)
{
if (items.items.key == key)
{
items.items.value = value;
break;
}
}
return true;
}
} public class Items
{
[XmlElement("item", typeof(Item))]
public Item[] items;
} public class Item
{
[XmlAttribute("key")]
public string key = string.Empty;
[XmlText]
public string value = string.Empty;
} internal class ResourcesSerializer
{
public static Resources DeSerialize(string filePath)
{
System.Xml.Serialization.XmlSerializer XmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Resources));
System.IO.FileStream FileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
Resources Resources = XmlSerializer.Deserialize(FileStream) as Resources;
FileStream.Close();
return Resources;
} public static void Serialize(string filePath, Resources Resources)
{
System.Xml.Serialization.XmlSerializer XmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Resources));
System.IO.FileStream FileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create);
XmlSerializer.Serialize(FileStream, Resources);
FileStream.Close();
}
}
}
[XML] Resource帮助类的更多相关文章
- 8 -- 深入使用Spring -- 3...1 Resource实现类ServletContextResource
8.3.1 Resource实现类------ServletContextResource:访问相对于ServletContext路径下的资源的实现类. 4.访问应用相关资源 Spring提供了Ser ...
- 8 -- 深入使用Spring -- 3...1 Resource实现类FileSystemResource
8.3.1 Resource实现类------FileSystemResource:访问文件系统的资源的实现类 3.访问文件系统资源 Spring提供的FileSystemResource类用于访问文 ...
- 8 -- 深入使用Spring -- 3...1 Resource实现类ClassPathResource
8.3.1 Resource实现类------ClassPathResource : 访问类加载路径下的资源的实现类 2.访问类加载路径下的资源 ClassPathResource 用来访问类加载路径 ...
- 8 -- 深入使用Spring -- 3...1 Resource实现类UrlResource
8.3.1 Resource 实现类------UrlResource : 访问网络资源的实现类 1.访问网络资源 访问网络资源通过UrlResource 类实现,UrlResource是java.n ...
- 阶段3 1.Mybatis_03.自定义Mybatis框架_4.自定义mybatis的编码-解析XML的工具类介绍
导入xml操作的类和用到的相关包 创建util包,然后把提供好的XMLConfigBuilder.java文件复制3过来 复制过来,里面用到了很多dom4j的东西 打开pom.xml 输入depend ...
- 让Visual Studio 2013为你自动生成XML反序列化的类
Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: 1. 在代码编辑界面的右侧滚动条上显示不同颜色的标签,让开发人员可以对所编辑文档的修改.查找.定位情 ...
- XML格式示例 与 XML操作(读取)类封装
header('Content-Type: text/xml'); <?xml version="1.0" encoding="utf-8" standa ...
- c# XML和实体类之间相互转换(序列化和反序列化)[砖]
link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...
- C# XML和实体类之间相互转换(序列化和反序列化)
我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...
随机推荐
- bzoj1232
由题意知,最后要保留的边肯定都要被走过 来回一条边所花费的时间=2*边长+安慰边两端的牛所要花的时间和 总时间就等于所保留边来回的时间和+根节点时间: 不难想到做一下最小生成树即可 贪心可知,根一定选 ...
- bzoj1263
观察可得,最大的拆分方法是尽量拆成3,特殊的,如果最后剩下了1,那么就把3+1变成2+2 然后高精度计算即可 var s2,s3,i,n,l:longint; a:..] of longint ...
- C# 利用BarcodeLib.dll生成条形码
首先效果: 1:首先下载BarcodeLib.dll 下载地址 http://pan.baidu.com/share/link?shareid=2590968386&uk=2148890391 ...
- format 对整形的应用
对于整型数,会在整型值的前面以0补之 Format('this is %.7d'[1234]); 输出是:this is 0001234]
- c语言的label后面不能直接跟变量申明
; goto JUMP; printf("x is : %d\n",x); JUMP: ; <=== 错误,lable后面不能申明变量,只能是表达式语句(statement) ...
- C++域宽设置
域宽设置,域宽填充; 设置域宽, cout<<set[w-width](int n)<<被设置的输出内容 设置填充字符, cout<<setfill(char n) ...
- cygwin下安装hadoop0.20
安装时选择软件包: editor-两个VIM.base-SED.Net-OPENSSH.OPENSSL.libs-libintl3和libintl8 环境变量: path=%JAVA_HOME%\bi ...
- 解决@media screen (自适应)IE浏览器不兼容问题
1.解决兼容性问题 (1)页面最顶部必须定义:<!DOCTYPE html> (2)点击:下载 respond.js 文件 (3)引入<script src="respon ...
- mysql技术调优资料整理
1,15 个有用的 MySQL/MariaDB 性能调整和优化技巧 2,MariaDB设置主从复制 3,CentOS6.4安装mysql2redis http://www.cnblogs ...
- SVN工具的使用 和在Eclipse中安装GPD插件:(多步审批流,因此选择使用工作流(JBPM)来实现)
前言 重点解说SVN工具的还原版本号. 1.提交svn之前.要先更新文件.假设更新之后有版本号冲突的话.就线下解决掉冲突,在把该文件标记为已经解决冲突. 正文 使用SVN还原历史版本号 water ...