Op Englesch liesen Editéieren

Deelen iwwer


ResourceManager.BaseName Property

Definition

Gets the root name of the resource files that the ResourceManager searches for resources.

C#
public virtual string BaseName { get; }

Property Value

The root name of the resource files that the ResourceManager searches for resources.

Examples

You can determine the names of embedded .resources files by compiling and running the following utility. This is a console app that accepts the name of a main assembly or satellite assembly as a command-line parameter. It displays the strings that should be provided as the baseName parameter of the ResourceManager(String, Assembly) or ResourceManager(String, Assembly, Type) constructor so that the resource manager can correctly identify the resource.

C#
using System;
using System.IO;
using System.Reflection;
using System.Resources;

public class Example
{
   public static void Main()
   {
      if (Environment.GetCommandLineArgs().Length == 1) { 
         Console.WriteLine("No filename.");
         return;
      }
      
      string filename = Environment.GetCommandLineArgs()[1].Trim();
      // Check whether the file exists.
      if (!File.Exists(filename)) {
         Console.WriteLine("{0} does not exist.", filename);
         return;
      }   
      
      // Try to load the assembly.
      Assembly assem = Assembly.LoadFrom(filename);
      Console.WriteLine("File: {0}", filename);
         
      // Enumerate the resource files.
      string[] resNames = assem.GetManifestResourceNames();
      if (resNames.Length == 0)
         Console.WriteLine("   No resources found.");

      foreach (var resName in resNames)
         Console.WriteLine("   Resource: {0}", resName.Replace(".resources", ""));

      Console.WriteLine();
   }
}

Remarks

The BaseName property reflects the fully qualified namespace name and the root resource name of a resource file, without its culture or file name extension. For example, if an app's default resource file is named SampleApps.StringResources.resources, the value of the BaseName property is "SampleApps.StringResources". If an app's default resource file is named SampleApps.StringResources.en-US.resources and is embedded in a satellite assembly, the value of the BaseName property is still "SampleApps.StringResources".

Wichteg

The BaseName property value of a resource file that is compiled and embedded from the command line does not include a namespace name unless you explicitly include one when compiling the file. On the other hand, the BaseName property value of a resource file that is compiled and embedded within the Visual Studio environment typically does include the default namespace name.

The BaseName property value is the same as the string passed to the ResourceManager(String, Assembly) or ResourceManager(String, Assembly, Type) constructor when instantiating a ResourceManager instance.

Applies to

Produkt Versiounen
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1