zoukankan      html  css  js  c++  java
  • [XML] Resource帮助类

    点击下载 Resources.rar

    /// <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 = 0; 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 = 0; 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();
            }
        }
    }
  • 相关阅读:
    VMware WorkStation 用 VMTools 官方下载地址 windows-vmtools tools-windows
    LeetCode Golang 9.回文数
    CentOS6.5中配置Rabbitmq3.6.6集群方案
    python之lambda、filter、map、reduce的用法讲解
    跨主机容器之间通信实现方式:etcd+flanned
    mongo3.4安装
    centos 时区的更改 UTC TO CST
    Elasticsearch5安装
    docker1.*.*版本安装
    使用weave来实现多宿主机中的docker容器之间通信
  • 原文地址:https://www.cnblogs.com/lizeyan/p/3628823.html
Copyright © 2011-2022 走看看