点击下载 Resources.rar

  1. /// <summary>
  2. /// 类说明:Resources
  3. /// 编 码 人:苏飞
  4. /// 联系方式:361983679
  5. /// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
  6. /// </summary>
  7.  
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Xml;
  11. using System.Xml.Serialization;
  12.  
  13. namespace DotNet.Utilities
  14. {
  15. /// <summary>
  16. /// BUResourceManager
  17. /// 资源管理器
  18. /// </author>
  19. /// </summary>
  20. [XmlRoot("resources")]
  21. public class Resources
  22. {
  23. private SortedList<String, String> indexs = new SortedList<String, String>();
  24.  
  25. [XmlElement("language")]
  26. public string language = string.Empty;
  27. [XmlElement("displayName")]
  28. public string displayName = string.Empty;
  29. [XmlElement("version")]
  30. public string version = string.Empty;
  31. [XmlElement("author")]
  32. public string author = string.Empty;
  33. [XmlElement("description")]
  34. public string description = string.Empty;
  35. [XmlElement("items", typeof(Items))]
  36. public Items items;
  37.  
  38. public void createIndex()
  39. {
  40. indexs.Clear();
  41. if (items == null)
  42. {
  43. return;
  44. }
  45. indexs = new SortedList<String, String>(items.items.Length);
  46. for (int i = ; i < items.items.Length; i++)
  47. {
  48. #if DEBUG
  49. try
  50. {
  51. [i] indexs.Add(items.items.key, items.items.value);
  52. }
  53. catch
  54. {
  55. throw (new Exception(items.items.key + items.items.value));
  56. }
  57. #else
  58. indexs.Add(items.items.key, items.items.value);
  59. #endif
  60. }
  61. }
  62.  
  63. public string Get(string key)
  64. {
  65. if (!indexs.ContainsKey(key))
  66. {
  67. return string.Empty;
  68. }
  69. return indexs[key];
  70. }
  71.  
  72. /// <summary>
  73. /// JiRiGaLa 2007.05.02
  74. /// </summary>
  75. /// <param name="key"></param>
  76. /// <param name="value"></param>
  77. /// <returns></returns>
  78. public bool Set(string key, string value)
  79. {
  80. if (!indexs.ContainsKey(key))
  81. {
  82. return false;
  83. }
  84. indexs[key] = value;
  85. for (int i = ; i < items.items.Length; i++)
  86. {
  87. if (items.items.key == key)
  88. {
  89. items.items.value = value;
  90. break;
  91. }
  92. }
  93. return true;
  94. }
  95. }
  96.  
  97. public class Items
  98. {
  99. [XmlElement("item", typeof(Item))]
  100. public Item[] items;
  101. }
  102.  
  103. public class Item
  104. {
  105. [XmlAttribute("key")]
  106. public string key = string.Empty;
  107. [XmlText]
  108. public string value = string.Empty;
  109. }
  110.  
  111. internal class ResourcesSerializer
  112. {
  113. public static Resources DeSerialize(string filePath)
  114. {
  115. System.Xml.Serialization.XmlSerializer XmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Resources));
  116. System.IO.FileStream FileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
  117. Resources Resources = XmlSerializer.Deserialize(FileStream) as Resources;
  118. FileStream.Close();
  119. return Resources;
  120. }
  121.  
  122. public static void Serialize(string filePath, Resources Resources)
  123. {
  124. System.Xml.Serialization.XmlSerializer XmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Resources));
  125. System.IO.FileStream FileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create);
  126. XmlSerializer.Serialize(FileStream, Resources);
  127. FileStream.Close();
  128. }
  129. }
  130. }

[XML] Resource帮助类的更多相关文章

  1. 8 -- 深入使用Spring -- 3...1 Resource实现类ServletContextResource

    8.3.1 Resource实现类------ServletContextResource:访问相对于ServletContext路径下的资源的实现类. 4.访问应用相关资源 Spring提供了Ser ...

  2. 8 -- 深入使用Spring -- 3...1 Resource实现类FileSystemResource

    8.3.1 Resource实现类------FileSystemResource:访问文件系统的资源的实现类 3.访问文件系统资源 Spring提供的FileSystemResource类用于访问文 ...

  3. 8 -- 深入使用Spring -- 3...1 Resource实现类ClassPathResource

    8.3.1 Resource实现类------ClassPathResource : 访问类加载路径下的资源的实现类 2.访问类加载路径下的资源 ClassPathResource 用来访问类加载路径 ...

  4. 8 -- 深入使用Spring -- 3...1 Resource实现类UrlResource

    8.3.1 Resource 实现类------UrlResource : 访问网络资源的实现类 1.访问网络资源 访问网络资源通过UrlResource 类实现,UrlResource是java.n ...

  5. 阶段3 1.Mybatis_03.自定义Mybatis框架_4.自定义mybatis的编码-解析XML的工具类介绍

    导入xml操作的类和用到的相关包 创建util包,然后把提供好的XMLConfigBuilder.java文件复制3过来 复制过来,里面用到了很多dom4j的东西 打开pom.xml 输入depend ...

  6. 让Visual Studio 2013为你自动生成XML反序列化的类

    Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: 1. 在代码编辑界面的右侧滚动条上显示不同颜色的标签,让开发人员可以对所编辑文档的修改.查找.定位情 ...

  7. XML格式示例 与 XML操作(读取)类封装

    header('Content-Type: text/xml'); <?xml version="1.0" encoding="utf-8" standa ...

  8. c# XML和实体类之间相互转换(序列化和反序列化)[砖]

    link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...

  9. C# XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...

随机推荐

  1. C++ Prime:范围for语句

    C++11新标准引入了一种更简单的for语句,这种语句可以遍历容器或者其他序列的所有元素.范围for语句的语法形式是: for( declaration : expression) statement ...

  2. oracle 10g WMSYS.WM_CONCAT 函數的用法

    select t.rank, t.Name from t_menu_item t; 10 CLARK 10 KING 10 MILLER 20 ADAMS 20 FORD 20 JONES 20 SC ...

  3. 【转】 Android BCM4330 蓝牙BT驱动调试记录

    原文网址:http://blog.csdn.net/dwyane_zhang/article/details/7180779 网上关于BT的驱动很少,所以我在开发过程中把其中的步骤记录下来.供大家相互 ...

  4. SharePoint 2010中使用SPListItemCollectionPosition更快的结果

    转:http://www.16kan.com/article/detail/318657.html Introduction介绍 In this article we will explore the ...

  5. oracle的基本信息查询

    oracle查看当前数据库实例名 select name from V$DATABASE; 或者 select SYS_CONTEXT('USERENV','INSTANCE_NAME') from ...

  6. apache的FileUtils方法大全

    FileUtils 获取系统的临时目录路径:getTempDirectoryPath() [java] view plaincopyprint? public static String getTem ...

  7. HTML5 Canvas核心技术—图形、动画与游戏开发.pdf8

    第6章 精灵 精灵(sprite),它是一种可以集成入动画之中的图像对象,赋予它们各种行为,精灵并非Canvas API的一部分,,但都是从它衍生而来 本章将会实现三种设计模式:策略模式(精灵与绘制器 ...

  8. javascript日志框架使用

    1.在页面中引入js文件 官网:http://log4javascript.org/index.html ```javascript <script src="http://cdn.b ...

  9. UIWebview 禁止某个方向滚动

    Enable Horizontal scrolling and disable Vertical scrolling: myWebView.scrollView.delegate = self; [m ...

  10. Uber能知道你是不是在开车的时候玩手机

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...