ResXResourceReader.BasePath 속성

정의

ResXFileRef 개체에 지정된 상대 파일 경로의 기본 경로를 가져오거나 설정합니다.

public:
 property System::String ^ BasePath { System::String ^ get(); void set(System::String ^ value); };
public string BasePath { get; set; }
public string? BasePath { get; set; }
member this.BasePath : string with get, set
Public Property BasePath As String

속성 값

ResXFileRef 개체에 지정된 상대 파일 경로 앞에 추가될 경우 리소스 파일의 절대 경로를 생성하는 경로입니다.

예외

set 작업에서, XML 리소스 파일이 이미 액세스되어 사용 중이기 때문에 값을 지정할 수 없는 경우

예제

다음 예제에서는 품종의 이미지를 포함 하는 리소스를 만든 애플리케이션을 지정 하는 문자열 리소스를 만듭니다 XML 리소스 파일을 만듭니다. ResXFileRef 개체는 리소스 파일에 이진 이미지 자체를 저장하는 대신 이미지의 경로를 저장하는 데 사용됩니다. 이 예제에서는 이미지의 파일 이름에 있는 상대 파일 경로가 C:\data\라는 디렉터리의 하위 디렉터리로 해석되도록 속성을 설정합니다 BasePath .

using System;
using System.Collections;
using System.ComponentModel.Design;
using System.Drawing;
using System.Reflection;
using System.Resources;

public class Example
{
   public static void Main()
   {
      CreateXMLResourceFile();
      
      // Read the resources in the XML resource file.
      ResXResourceReader resx = new ResXResourceReader("DogBreeds.resx"); 
      Console.WriteLine("Default Base Path: '{0}'", resx.BasePath);
      resx.BasePath = @"C:\Data\";
      Console.WriteLine("Current Base Path: '{0}'\n", resx.BasePath); 
      resx.UseResXDataNodes = true;

      IDictionaryEnumerator dict = resx.GetEnumerator();
      AssemblyName[] assemblyNames = { new AssemblyName(typeof(Bitmap).Assembly.FullName) };
      while (dict.MoveNext()) {
         ResXDataNode node = (ResXDataNode) dict.Value;
         if (node.FileRef != null) {
            object image = node.GetValue(assemblyNames);
            Console.WriteLine("{0}: {1} from {2}", dict.Key, 
                              image.GetType().Name, node.FileRef.FileName);
         }
         else {
            Console.WriteLine("{0}: {1}", node.Name, node.GetValue((ITypeResolutionService) null));
         }   
      }   
   }

   private static void CreateXMLResourceFile()
   {
      // Define an array of ResXFileRef objects for images.
      String typeName = String.Format("{0}, {1}", typeof(Bitmap).FullName, 
                                      typeof(Bitmap).Assembly.FullName);
      ResXFileRef[] imageRefs =
         { new ResXFileRef(@"images\Akita.jpg", typeName),
           new ResXFileRef(@"images\Dalmatian.jpg", typeName),
           new ResXFileRef(@"images\Husky.jpg", typeName),
           new ResXFileRef(@"images\GreatPyrenees.jpg", typeName),
           new ResXFileRef(@"images\Malamute.jpg", typeName),
           new ResXFileRef(@"images\newfoundland.jpg", typeName),
           new ResXFileRef(@"images\Rottweiler.jpg", typeName) 
         };
      
      using (ResXResourceWriter resx = new ResXResourceWriter(@".\DogBreeds.resx")) {
         // Add each ResXFileRef object to the resource file.
         foreach (var imageRef in imageRefs) {
            // Form resource name from name of image.
            String name = imageRef.FileName;
            name = name.Substring(name.IndexOf(@"\") + 1);
            name = name.Substring(0, name.IndexOf("."));
            ResXDataNode node = new ResXDataNode(name, imageRef); 
            resx.AddResource(node);
         }
         resx.AddResource("CreatedBy", typeof(Example).Assembly.FullName);
      }   
   }
}
// The example displays the following output:
//    Default Base Path: ''
//    Current Base Path: 'C:\Data\'
//    
//    Akita: Bitmap from C:\Data\images\Akita.jpg
//    Dalmatian: Bitmap from C:\Data\images\Dalmatian.jpg
//    Husky: Bitmap from C:\Data\images\Husky.jpg
//    GreatPyrenees: Bitmap from C:\Data\images\GreatPyrenees.jpg
//    Malamute: Bitmap from C:\Data\images\Malamute.jpg
//    newfoundland: Bitmap from C:\Data\images\newfoundland.jpg
//    Rottweiler: Bitmap from C:\Data\images\Rottweiler.jpg
//    CreatedBy: BasePathEx1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Imports System.Collections
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Reflection
Imports System.Resources

Module Example
   Public Sub Main()
      CreateXMLResourceFile()
      
      ' Read the resources in the XML resource file.
      Dim resx As New ResXResourceReader("DogBreeds.resx") 
      Console.WriteLine("Default Base Path: '{0}'", resx.BasePath)
      resx.BasePath = "C:\Data\"
      Console.WriteLine("Current Base Path: '{0}'", resx.BasePath) 
      Console.WriteLine()     
      resx.UseResXDataNodes = True

      Dim dict As IDictionaryEnumerator = resx.GetEnumerator()
      Dim assemblyNames() As AssemblyName = 
                       { New AssemblyName(GetType(Bitmap).Assembly.FullName) }
      Do While dict.MoveNext()
         Dim node As ResXDataNode = CType(dict.Value, ResXDataNode)
         If node.FileRef IsNot Nothing Then
            Dim image As Object = node.GetValue(assemblyNames)
            Console.WriteLine("{0}: {1} from {2}", dict.Key, image.GetType().Name, node.FileRef.Filename)
         Else
            Console.WriteLine("{0}: {1}", node.Name, node.GetValue(CType(Nothing, ITypeResolutionService)))
         End If   
      Loop   
   End Sub
   
   Private Sub CreateXMLResourceFile()
      ' Define an array of ResXFileRef objects for images.
      Dim typeName As String = String.Format("{0}, {1}", GetType(Bitmap).Fullname, GetType(Bitmap).Assembly.FullName)
      Dim imageRefs() As ResXFileRef =
         { New ResXFileRef("images\Akita.jpg", typeName),
           New ResXFileRef("images\Dalmatian.jpg", typeName),
           New ResXFileRef("images\Husky.jpg", typeName),
           New ResXFileRef("images\GreatPyrenees.jpg", typeName),
           New ResXFileRef("images\Malamute.jpg", typeName),
           New ResXFileRef("images\Newfoundland.jpg", typeName),
           New ResXFileRef("images\Rottweiler.jpg", typeName) 
         }
      
      Using resx As New ResXResourceWriter(".\DogBreeds.resx")
         ' Add each ResXFileRef object to the resource file.
         For Each imageRef In imageRefs
            ' Form resource name from name of image.
            Dim name As String = imageRef.FileName
            name = name.Substring(name.IndexOf("\") + 1)
            name = name.Substring(0, name.IndexOf("."))
            Dim node As New ResXDataNode(name, imageRef) 
            resx.AddResource(node)
         Next
         resx.AddResource("CreatedBy", GetType(Example).Assembly.FullName)
      End Using   
   End Sub
End Module
' The example displays the following output:
'       Default Base Path: ''
'       Current Base Path: 'C:\Data\'
'       
'       Akita: Bitmap from C:\Data\images\Akita.jpg
'       Dalmatian: Bitmap from C:\Data\images\Dalmatian.jpg
'       Husky: Bitmap from C:\Data\images\Husky.jpg
'       GreatPyrenees: Bitmap from C:\Data\images\GreatPyrenees.jpg
'       Malamute: Bitmap from C:\Data\images\Malamute.jpg
'       Newfoundland: Bitmap from C:\Data\images\Newfoundland.jpg
'       Rottweiler: Bitmap from C:\Data\images\Rottweiler.jpg
'       CreatedBy: BasePathEx1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

프로젝트를 성공적으로 컴파일하려면 System.Drawing.dll 대한 참조를 추가해야 합니다. 또한 이 예제에서는 필요한 이미지가 C:\data\images\라는 디렉터리에 있어야 합니다.

설명

속성은 BasePath 개체의 ResXFileRef 속성에 할당된 상대 파일 경로 참조를 resolve 데 FileName 사용됩니다. 기본적으로 해당 값은 이며 String.Empty상대 파일 경로 참조는 속성에서 반환 Environment.CurrentDirectory 된 현재 디렉터리와의 관계에서 확인됩니다. 리소스 열거를 시작하기 전에 이 속성을 설정해야 합니다.

적용 대상

추가 정보