About 2005 resources

xiaoxiao2021-03-19  205

There are two fixed folders app_globalresources and app_localResources in ASP.NET, where app_globalResources will be compiled into app_globalResources.dll, which is used to store public resources, and App_localResources does not perform compilation and is used to store their own resources. In the base class TemplateControl of Page and UserControl, both GetGlobalResourceObject and GetLocalResourceObject two functions can be called directly (there are two equally static methods in HTTPContext) to achieve the specified resources. For example: There is a Test.Strings.resX resource file in App_GlobalResources, with a resource named S, you can use getGlobalResourceObject ("Test.strings", "S") to get it, where there is no specified what kind of Language resources, this will use the language in Thread.CurrentThread.Currentuicultuicultuicultuicultuiculture, you can also set the value of thread.currentthread.currentuicultuicultuicultuicuiculicu before use. There is no test.strings.resx this file, directly using Test.Strings.zh-cn.resx, test.strings.en-us.resx ... and other files. There are many ways to get resources, here is written, and different must have Test.Strings.resx this file. Can be used directly Resources.test.strings.s to get resources like this do not feel flexible and can mimic GetGlobalResourceObject way to write a GetGlobalResourceString method as follows: private string GetGlobalResourceString (string className, string resourceKey) {Type type = GetResourceType (className) ; //Type.getproperty ("culture ").SetValue (NULL, New CultureInfo (" zh-cn "), null;

return type.GetProperty (resourceKey) .GetValue (null, null) as string;} private Type GetResourceType (string name) {Assembly ass = Assembly.Load ( "App_GlobalResources"); Type type = ass.GetType ( "Resources." Name); Return Type;}

转载请注明原文地址:https://www.9cbs.com/read-130257.html

New Post(0)