Using ResourceManager

前端 未结 6 1216
走了就别回头了
走了就别回头了 2020-12-08 07:38

I\'m trying to use the ResourceManager in a C# class, but don\'t know what to substitute for the basename when creating a new instance of the ResourceManager class.

6条回答
  •  隐瞒了意图╮
    2020-12-08 07:52

    The quick and dirty way to check what string you need it to look at the generated .resources files.

    Your .resources are generated in the resources projects obj/Debug directory. (if not right click on .resx file in solution explorer and hit 'Run Custom Tool' to generate the .resources files)

    Navigate to this directory and have a look at the filenames. You should see a file ending in XYZ.resources. Copy that filename and remove the trailing .resources and that is the file you should be loading.

    For example in my obj/Bin directory I have the file:

    MyLocalisation.Properties.Resources.resources

    If the resource files are in the same Class library/Application I would use the following C#

    ResourceManager RM = new ResourceManager("MyLocalisation.Properties.Resources", Assembly.GetExecutingAssembly());
    

    However, as it sounds like you are using the resources file from a separate Class library/Application you probably want

    Assembly localisationAssembly = Assembly.Load("MyLocalisation");
    ResourceManager RM =  new ResourceManager("MyLocalisation.Properties.Resources", localisationAssembly);
    

提交回复
热议问题