关于2005的资源

        在ASP.net中有两个固定文件夹App_GlobalResources和App_LocalResources,其中App_GlobalResources会编译到App_GlobalResources.dll中,用于存放公用的资源,App_LocalResources不执行编译,用于存放各个页面自己的资源。在Page和UserControl的基类TemplateControl中新增了GetGlobalResourceObject和GetLocalResourceObject两个函数,可以在页面中直接调用(在HttpContext中也有两个同样的静态方法)以取得指定的资源。
        例如:在App_GlobalResources中有个test.strings.resx的资源文件,里面有条名为s的资源,则可以使用GetGlobalResourceObject("test.strings", "s")来取得它,这里没有指定取得何种语言的资源,这样的话将会使用Thread.CurrentThread.CurrentUICulture中的语言,自己也可以在使用之前设定Thread.CurrentThread.CurrentUICulture的值。可以没有test.strings.resx这个文件,直接使用test.strings.zh-cn.resx、test.strings.en-us.resx...等文件。
        还有很多方法可以取得资源,这里写出一个,不同的是必须有test.strings.resx这个文件。可以直接使用Resources.test.strings.s来取得资源,这样子做感觉不够灵活,可以模仿GetGlobalResourceObject方法写一个GetGlobalResourceString方法,如下:
None.gif      private   string  GetGlobalResourceString( string  className,  string  resourceKey)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        Type type 
= GetResourceType(className);
InBlock.gif        
//type.GetProperty("Culture").SetValue(null, new CultureInfo("zh-cn"), null);
InBlock.gif

InBlock.gif        
return type.GetProperty(resourceKey).GetValue(nullnullas string;
ExpandedBlockEnd.gif    }

None.gif    
private  Type GetResourceType( string  name)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        Assembly ass 
= Assembly.Load("App_GlobalResources");
InBlock.gif        Type type 
= ass.GetType("Resources." + name);
InBlock.gif        
return type;
ExpandedBlockEnd.gif    }
        Windows的资源下次在写吧
posted on 2005-12-20 09:33 Darrell Wang 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/DracoWang/archive/2005/12/20/300628.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值