有没有一种方法可以自动生成可以执行线程安全的文件,对资源进行特定区域性访问的文件? Visual Studio为我的resx文件生成的当前Resource.Designer.cs类如下:
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("microsoft.Performance","CA1811:AvoidUncalledPrivateCode")]
internal Resource()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager
{
get
{
if (object.ReferenceEquals(resourceMan,null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ServiceModels.Resource",typeof(Resource).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's Currentuiculture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Hiii.
/// </summary>
public static string Hello
{
get
{
return ResourceManager.GetString("Hello",resourceCulture);
}
}
这允许安全地访问“ Hello”资源,但是当使用不同区域性的不同资源文件时,它似乎不是线程安全的。例如,使用此代码,您可以通过
设置资源Culture = CultureInfo.SomeCulture;
这将使用ResourceManager设置所有线程的区域性。有没有一种方法可以自动生成一个文件,该文件允许线程安全,对资源进行特定区域性访问,或者我必须自己实现一个文件?