读取资源

using  System;
using  System.Xml;
using  System.Collections;
using  System.IO;
using  System.Text;
using  System.Resources;

using  Config;

namespace  Common
{
    
///   <summary>
    
///  Summary description for Message.
    
///   </summary>
     public   class  CMessage
    {
        
private   static  IDictionary dicMessages;

        
static  CMessage()
        {
            InitMessages();
        }

        
///   <summary>
        
///  初始化资源
        
///   </summary>
         private   static   void  InitMessages()
        {
            
if  (dicMessages  ==   null )
            {
                dicMessages 
=   new  Hashtable();
            }
            
using  (ResourceReader reader  =   new  ResourceReader(ConfigHelper.PhysicalRootPath  +   " bin\\ "   +  ConfigHelper.CultureInfo  +   " .resources " ))
            {
                
int  key  =   0 ;
                
foreach  (DictionaryEntry entry  in  reader)
                {
                    key 
=   int .Parse(entry.Key.ToString());
                    
if  ( ! dicMessages.Contains(key))
                    {
                        dicMessages.Add(key, entry.Value);
                    }
                }
            }
        }

        
public   static   string  Item( int  code)
        {
            
string  value  =   null ;
            
if  (dicMessages[code]  ==   null )
            {
                InitMessages();
                
if  (dicMessages[code]  ==   null )
                {
                    value 
=  code.ToString();
                }
                
else
                {
                    value 
=  dicMessages[code].ToString();
                }
            }
            
else
            {
                value 
=  dicMessages[code].ToString();
            }
            
return  value;
        }
    }
}

你可能感兴趣的:(读取)