ResX自动生成的文件,用于文化特定的资源访问

有没有一种方法可以自动生成可以执行线程安全的文件,对资源进行特定区域性访问的文件? 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设置所有线程的区域性。有没有一种方法可以自动生成一个文件,该文件允许线程安全,对资源进行特定区域性访问,或者我必须自己实现一个文件?

liuchongjun217 回答:ResX自动生成的文件,用于文化特定的资源访问

Thread.CurrentThread.CurrentCulture是特定于线程的Culture设置,大多数库都将其用于格式化日期/时间或数字,并在您的情况下用于获取翻译的字符串。

https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.currentculture?view=netframework-4.8

本文链接:https://www.f2er.com/2676112.html

大家都在问