博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[XML] ResourceManager一个操作Resource的帮助类 (转载)
阅读量:4561 次
发布时间:2019-06-08

本文共 3522 字,大约阅读时间需要 11 分钟。

/// /// 类说明:Assistant/// 编 码 人:苏飞/// 联系方式:361983679  /// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]///  using System;using System.Collections;using System.Collections.Generic;using System.IO; namespace DotNet.Utilities{    ///     /// ResourceManager    ///      ///     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
LanguageResources = new SortedList
(); 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
> 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); } }}

 

转载于:https://www.cnblogs.com/lizeyan/p/3628814.html

你可能感兴趣的文章
HttpWebResponse远程服务器返回错误: (500) 内部服务器错误
查看>>
关于.net MVC5+EF6 网站部署的问题
查看>>
异常 : identifier of an instance of com.mi.domain.Department was altered from 2 to 1
查看>>
实现托管代码调用非托管代码以及非托管代码调用托管代码->COM Interop
查看>>
简易乘方算法
查看>>
leetcode - Unique Paths
查看>>
舵机控制
查看>>
句柄类与继承
查看>>
cocos2d-x-3.1 事件分发机制 (coco2d-x 学习笔记七)
查看>>
多项式问题
查看>>
服务器实现的多种方法汇总
查看>>
理解jquery的$.extend()、$.fn和$.fn.extend()
查看>>
在线安装eclipse中html/jsp/xml editor插件 eclipseeditor
查看>>
MAC下彻底解决mysql无法插入和显示中文
查看>>
HDU 4456 Crowd
查看>>
Union和union all区别?
查看>>
map_multimap
查看>>
需要拿来看的技术书籍
查看>>
设置sublime text2/3中预览浏览器快捷键的方法
查看>>
算法答疑---递归实现表达式求值
查看>>