开发者

ASP.Net Localisation Performance

开发者 https://www.devze.com 2023-01-26 17:58 出处:网络
In ASP.Net you can create a resources file for each culture that you wish to support in your application.

In ASP.Net you can create a resources file for each culture that you wish to support in your application.

e.g. (in resource designer) HelloWorld = "Hello World"

You can then reference this resources file in code.

Label1.Text = Resources.General.HelloWorld

Note: General is the name of my general resources file.

This means that Visual Studio has compiled the resources so that you have type safe access to them (+ intellisense which is useful).

However, how efficient is th开发者_JAVA技巧is?

  • Does .Net create a class containing constants which are somehow dynamically linked in the pre-run compilation - so they are sort of "built in" to the assembly?

  • Or does it scan through a file (somewhere) when a resource is requested in order to gain the localised value.

It would seem that the 1st is more efficient if this is what happens. Does localisation add a performance overhead to your application. I suppose a "reasonable" performance hit is ok if the localisation adds worthwhile usability to the site.

Thanks.


Take a look into Resource.Designer.cs file.

Basically, VS.NET creates a class with static properties, which access localized resources via constant keys using ResourceManager class. All strings and other resources are stored as resources in separate (culture specific) satellite assemblies.

Depending on Thread.Current.CurrentUICulture, CLR loads corresponding satellite resource assembly.

As for performance, since ResourceManager caches resources in HashTable, it should be relatively fast.

0

精彩评论

暂无评论...
验证码 换一张
取 消