ResourceManager.BaseName Właściwość

Definicja

Pobiera nazwę główną plików zasobów, które wyszukują ResourceManager zasoby.

public:
 virtual property System::String ^ BaseName { System::String ^ get(); };
public virtual string BaseName { get; }
member this.BaseName : string
Public Overridable ReadOnly Property BaseName As String

Wartość właściwości

Główna nazwa plików zasobów, które wyszukują ResourceManager zasoby.

Przykłady

Nazwy osadzonych plików resources można określić, kompilując i uruchamiając następujące narzędzie. Jest to aplikacja konsolowa, która akceptuje nazwę głównego zestawu lub zestawu satelitarnego jako parametr wiersza polecenia. Wyświetla on ciągi, które powinny być podane jako baseName parametr ResourceManager(String, Assembly) konstruktora lub ResourceManager(String, Assembly, Type) , aby menedżer zasobów mógł poprawnie zidentyfikować zasób.

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();
   }
}
Imports System.IO
Imports System.Reflection
Imports System.Resources

Module Example
   Public Sub Main()
      If Environment.GetCommandLineArgs.Length = 1 Then 
         Console.WriteLine("No filename.")
         Exit Sub
      End If
      Dim filename As String = Environment.GetCommandLineArgs(1).Trim()
      ' Check whether the file exists.
      If Not File.Exists(filename) Then
         Console.WriteLine("{0} does not exist.", filename)
         Exit Sub
      End If   
      
      ' Try to load the assembly.
      Dim assem As Assembly = Assembly.LoadFrom(filename)
      Console.WriteLine("File: {0}", filename)
         
      ' Enumerate the resource files.
      Dim resNames() As String = assem.GetManifestResourceNames()
      If resNames.Length = 0 Then
         Console.WriteLine("   No resources found.")
      End If
      For Each resName In resNames
         Console.WriteLine("   Resource: {0}", resName.Replace(".resources", ""))
      Next
      Console.WriteLine()
   End Sub
End Module

Uwagi

Właściwość BaseName odzwierciedla w pełni kwalifikowaną nazwę przestrzeni nazw i nazwę głównego zasobu pliku zasobu bez jego rozszerzenia kultury lub nazwy pliku. Jeśli na przykład domyślny plik zasobu aplikacji ma nazwę SampleApps.StringResources.resources, wartość BaseName właściwości to "SampleApps.StringResources". Jeśli domyślny plik zasobu aplikacji ma nazwę SampleApps.StringResources.en-US.resources i jest osadzony w zestawie satelitarnym, wartość BaseName właściwości nadal wynosi "SampleApps.StringResources".

Ważne

BaseName Wartość właściwości pliku zasobu, który jest kompilowany i osadzony z wiersza polecenia, nie zawiera nazwy przestrzeni nazw, chyba że jawnie dołączysz go podczas kompilowania pliku. Z drugiej strony BaseName wartość właściwości pliku zasobu kompilowanego i osadzonego w środowisku programu Visual Studio zwykle zawiera domyślną nazwę przestrzeni nazw.

Wartość BaseName właściwości jest taka sama jak ciąg przekazywany do konstruktora ResourceManager(String, Assembly) lub ResourceManager(String, Assembly, Type) podczas tworzenia wystąpienia ResourceManager wystąpienia.

Dotyczy