• [XML] ResourceManager一个操作Resource的帮助类 (转载)


    点击下载 ResourceManager.zip

    /// <summary>
    /// 类说明:Assistant
    /// 编 码 人:苏飞
    /// 联系方式: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;
    using System.Collections.Generic;
    using System.IO;
     
    namespace DotNet.Utilities
    {
        /// <summary>
        /// ResourceManager
        /// </author> 
        /// </summary>
        public class ResourceManager
        {
            private volatile static ResourceManager instance = null;
            private static object locker = new Object();
            public static ResourceManager Instance
            {
                get
                {
                    if (instance == null)
                    {
                        lock (locker)
                        {
                            if (instance == null)
                            {
                                instance = new ResourceManager();
                            }
                        }
                    }
                    return instance;
                }
            }
     
            private string FolderPath = string.Empty;
            public SortedList<String, Resources> LanguageResources = new SortedList<String, Resources>();
     
            public void Serialize(Resources resources, string filePath)
            {
                ResourcesSerializer.Serialize(filePath, resources);
            }
     
            public void Init(string filePath)
            {
                FolderPath = filePath;
                DirectoryInfo directoryInfo = new DirectoryInfo(filePath);
                LanguageResources.Clear();
                if (!directoryInfo.Exists)
                {
                    return;
                }
                FileInfo[] FileInfo = directoryInfo.GetFiles();
                for (int i = 0; i < FileInfo.Length; i++)
                {
                    Resources resources = ResourcesSerializer.DeSerialize(FileInfo.FullName);
                    resources.createIndex();
                    LanguageResources.Add(resources.language, resources);     
                }
            }
     
            public Hashtable GetLanguages()
            {
                Hashtable hashtable = new Hashtable();
                IEnumerator<KeyValuePair<String, Resources>> iEnumerator = LanguageResources.GetEnumerator();
                while (iEnumerator.MoveNext())
                {
                    hashtable.Add(iEnumerator.Current.Key, iEnumerator.Current.Value.displayName);
                }
                return hashtable;
            }
     
            public Hashtable GetLanguages(string path)
            {
                Hashtable hashtable = new Hashtable();
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                if (!directoryInfo.Exists)
                {
                    return hashtable;
                }
                FileInfo[] fileInfo = directoryInfo.GetFiles();
                for (int i = 0; i < fileInfo.Length; i++)
                {
    [i]                Resources resources = ResourcesSerializer.DeSerialize(fileInfo.FullName);
                    hashtable.Add(resources.language, resources.displayName);
                }
                return hashtable;
            }
     
            public Resources GetResources(string filePath)
            {
                Resources resources = new Resources();
                if (File.Exists(filePath))
                {
                    resources = ResourcesSerializer.DeSerialize(filePath);
                    resources.createIndex();
                }
                return resources;
            }
                     
            public string Get(string language, string key)
            {
                if (!LanguageResources.ContainsKey(language))
                {
                    return string.Empty;
                }
                return LanguageResources[language].Get(key);
            }
        }
    }
  • 相关阅读:
    PHP配置文件处理类
    PHP中实现图片上传的类库
    在PHP中实现StringBuilder类
    微软官方及第三方SDK http://msdn.microsoft.com/zhcn/jj923044
    在PHP中模拟asp的response类
    Atitit.并发测试解决方案(2) 获取随机数据库记录 随机抽取数据 随机排序 原理and实现
    atitit. access token是什么??微信平台公众号开发access_token and Web session保持状态机制
    atitit.二进制数据无损转字符串网络传输
    atitit.重装系统需要备份的资料总结 o84..
    atitit.web ui 结构建模工具总结
  • 原文地址:https://www.cnblogs.com/lizeyan/p/3628814.html
Copyright © 2020-2023  润新知