ResXResourceWriter.AddResource 메서드

정의

기록할 리소스 목록에 리소스를 추가합니다.Adds a resource to the list of resources to write.

오버로드

AddResource(String, Object)

기록할 리소스 목록에 개체로 지정된 명명된 리소스를 추가합니다.Adds a named resource specified as an object to the list of resources to write.

AddResource(String, String)

리소스에 문자열 리소스를 추가합니다.Adds a string resource to the resources.

AddResource(ResXDataNode)

작성할 리소스 목록에 ResXDataNode 개체에 지정된 명명된 리소스를 추가합니다.Adds a named resource specified in a ResXDataNode object to the list of resources to write.

AddResource(String, Byte[])

기록할 리소스 목록에 바이트 배열로 지정된 명명된 리소스를 추가합니다.Adds a named resource specified as a byte array to the list of resources to write.

AddResource(String, Object)

기록할 리소스 목록에 개체로 지정된 명명된 리소스를 추가합니다.Adds a named resource specified as an object to the list of resources to write.

public:
 virtual void AddResource(System::String ^ name, System::Object ^ value);
public void AddResource (string name, object value);
abstract member AddResource : string * obj -> unit
override this.AddResource : string * obj -> unit
Public Sub AddResource (name As String, value As Object)

매개 변수

name
String

리소스의 이름입니다.The name of the resource.

value
Object

리소스의 값입니다.The value of the resource.

구현

예제

다음 예제에서는 라는.resx 파일을 만듭니다 CarResources.resx 문자열 6 개, 아이콘 및 두 개의 애플리케이션 정의 개체를 저장 하는 (두 Automobile 개체).The following example creates a .resx file named CarResources.resx that stores six strings, an icon, and two application-defined objects (two Automobile objects). 아이콘 및 Automobile 개체를 저장 하기 위해 AddResource(String, Object) 메서드를 호출 합니다.To store the icon and the Automobile objects, it calls the AddResource(String, Object) method. 이 예제에서 정의되고 인스턴스화된 Automobile 클래스는 SerializableAttribute 특성으로 태그가 지정됩니다.Note that the Automobile class, which is defined and instantiated in the example, is tagged with the SerializableAttribute attribute.

using System;
using System.Drawing;
using System.Resources;

[Serializable()] public class Automobile
{
   private string carMake;
   private string carModel;
   private int carYear;
   private int carDoors;
   private int carCylinders;
   
   public Automobile(string make, string model, int year) :  
                     this(make, model, year, 0, 0)   
   { }
   
   public Automobile(string make, string model, int year, 
                     int doors, int cylinders)
   {                     
      this.carMake = make;
      this.carModel = model;
      this.carYear = year;
      this.carDoors = doors;
      this.carCylinders = cylinders;
   }

   public string Make {
      get { return this.carMake; }
   }       
   
   public string Model {
      get {return this.carModel; }
   }       
   
   public int Year {
      get { return this.carYear; }
   }       
   
   public int Doors {
      get { return this.carDoors; }
   }       
   
   public int Cylinders {
      get { return this.carCylinders; }
   }       
}

public class Example
{
   public static void Main()
   {
      // Instantiate an Automobile object.
      Automobile car1 = new Automobile("Ford", "Model N", 1906, 0, 4);
      Automobile car2 = new Automobile("Ford", "Model T", 1909, 2, 4);
      // Define a resource file named CarResources.resx.
      using (ResXResourceWriter resx = new ResXResourceWriter(@".\CarResources.resx"))
      {
         resx.AddResource("Title", "Classic American Cars");
         resx.AddResource("HeaderString1", "Make");
         resx.AddResource("HeaderString2", "Model");
         resx.AddResource("HeaderString3", "Year");
         resx.AddResource("HeaderString4", "Doors");
         resx.AddResource("HeaderString5", "Cylinders");
         resx.AddResource("Information", SystemIcons.Information); 
         resx.AddResource("EarlyAuto1", car1);  
         resx.AddResource("EarlyAuto2", car2);  
      }
   }
}
Imports System.Drawing
Imports System.Resources

<Serializable()> Public Class Automobile
   Private carMake As String
   Private carModel As String
   Private carYear As Integer
   Private carDoors AS Integer
   Private carCylinders As Integer
   
   Public Sub New(make As String, model As String, year As Integer) 
      Me.New(make, model, year, 0, 0)   
   End Sub
   
   Public Sub New(make As String, model As String, year As Integer, 
                  doors As Integer, cylinders As Integer)
      Me.carMake = make
      Me.carModel = model
      Me.carYear = year
      Me.carDoors = doors
      Me.carCylinders = cylinders
   End Sub

   Public ReadOnly Property Make As String
      Get
         Return Me.carMake
      End Get   
   End Property       
   
   Public ReadOnly Property Model As String
      Get
         Return Me.carModel
      End Get   
   End Property       
   
   Public ReadOnly Property Year As Integer
      Get
         Return Me.carYear
      End Get   
   End Property       
   
   Public ReadOnly Property Doors As Integer
      Get
         Return Me.carDoors
      End Get   
   End Property       
   
   Public ReadOnly Property Cylinders As Integer
      Get
         Return Me.carCylinders
      End Get   
   End Property       
End Class

Module Example
   Public Sub Main()
      ' Instantiate an Automobile object.
      Dim car1 As New Automobile("Ford", "Model N", 1906, 0, 4)
      Dim car2 As New Automobile("Ford", "Model T", 1909, 2, 4)
      ' Define a resource file named CarResources.resx.
      Using resx As New ResXResourceWriter(".\CarResources.resx")
         resx.AddResource("Title", "Classic American Cars")
         resx.AddResource("HeaderString1", "Make")
         resx.AddResource("HeaderString2", "Model")
         resx.AddResource("HeaderString3", "Year")
         resx.AddResource("HeaderString4", "Doors")
         resx.AddResource("HeaderString5", "Cylinders")
         resx.AddResource("Information", SystemIcons.Information) 
         resx.AddResource("EarlyAuto1", car1)
         resx.AddResource("EarlyAuto2", car2)  
      End Using
   End Sub
End Module

설명

Generate를 호출할 때까지 리소스가 기록 되지 않습니다.The resource is not written until Generate is called. 추가 된 리소스는 serializable 이어야 합니다.The resource that was added must be serializable.

문자열을으로 쓰기 추가 되는 리소스가 문자열인 경우 이 고, 그렇지 리소스 이며 직렬화 된 이진 형식으로 저장 합니다.If the resource being added is a string, it is written as a string; otherwise, the resource is serialized and stored in a binary format.

AddResource(String, String)

리소스에 문자열 리소스를 추가합니다.Adds a string resource to the resources.

public:
 virtual void AddResource(System::String ^ name, System::String ^ value);
public void AddResource (string name, string value);
abstract member AddResource : string * string -> unit
override this.AddResource : string * string -> unit
Public Sub AddResource (name As String, value As String)

매개 변수

name
String

리소스의 이름입니다.The name of the resource.

value
String

리소스의 값입니다.The value of the resource.

구현

예제

다음 예제에서는 라는.resx 파일을 만듭니다 CarResources.resx 문자열 6 개, 아이콘 및 두 개의 애플리케이션 정의 개체를 저장 하는 (두 Automobile 개체).The following example creates a .resx file named CarResources.resx that stores six strings, an icon, and two application-defined objects (two Automobile objects). 문자열을 저장 하기 위해 AddResource(String, String) 메서드를 호출 합니다.To store the strings, it calls the AddResource(String, String) method.

using System;
using System.Drawing;
using System.Resources;

[Serializable()] public class Automobile
{
   private string carMake;
   private string carModel;
   private int carYear;
   private int carDoors;
   private int carCylinders;
   
   public Automobile(string make, string model, int year) :  
                     this(make, model, year, 0, 0)   
   { }
   
   public Automobile(string make, string model, int year, 
                     int doors, int cylinders)
   {                     
      this.carMake = make;
      this.carModel = model;
      this.carYear = year;
      this.carDoors = doors;
      this.carCylinders = cylinders;
   }

   public string Make {
      get { return this.carMake; }
   }       
   
   public string Model {
      get {return this.carModel; }
   }       
   
   public int Year {
      get { return this.carYear; }
   }       
   
   public int Doors {
      get { return this.carDoors; }
   }       
   
   public int Cylinders {
      get { return this.carCylinders; }
   }       
}

public class Example
{
   public static void Main()
   {
      // Instantiate an Automobile object.
      Automobile car1 = new Automobile("Ford", "Model N", 1906, 0, 4);
      Automobile car2 = new Automobile("Ford", "Model T", 1909, 2, 4);
      // Define a resource file named CarResources.resx.
      using (ResXResourceWriter resx = new ResXResourceWriter(@".\CarResources.resx"))
      {
         resx.AddResource("Title", "Classic American Cars");
         resx.AddResource("HeaderString1", "Make");
         resx.AddResource("HeaderString2", "Model");
         resx.AddResource("HeaderString3", "Year");
         resx.AddResource("HeaderString4", "Doors");
         resx.AddResource("HeaderString5", "Cylinders");
         resx.AddResource("Information", SystemIcons.Information); 
         resx.AddResource("EarlyAuto1", car1);  
         resx.AddResource("EarlyAuto2", car2);  
      }
   }
}
Imports System.Drawing
Imports System.Resources

<Serializable()> Public Class Automobile
   Private carMake As String
   Private carModel As String
   Private carYear As Integer
   Private carDoors AS Integer
   Private carCylinders As Integer
   
   Public Sub New(make As String, model As String, year As Integer) 
      Me.New(make, model, year, 0, 0)   
   End Sub
   
   Public Sub New(make As String, model As String, year As Integer, 
                  doors As Integer, cylinders As Integer)
      Me.carMake = make
      Me.carModel = model
      Me.carYear = year
      Me.carDoors = doors
      Me.carCylinders = cylinders
   End Sub

   Public ReadOnly Property Make As String
      Get
         Return Me.carMake
      End Get   
   End Property       
   
   Public ReadOnly Property Model As String
      Get
         Return Me.carModel
      End Get   
   End Property       
   
   Public ReadOnly Property Year As Integer
      Get
         Return Me.carYear
      End Get   
   End Property       
   
   Public ReadOnly Property Doors As Integer
      Get
         Return Me.carDoors
      End Get   
   End Property       
   
   Public ReadOnly Property Cylinders As Integer
      Get
         Return Me.carCylinders
      End Get   
   End Property       
End Class

Module Example
   Public Sub Main()
      ' Instantiate an Automobile object.
      Dim car1 As New Automobile("Ford", "Model N", 1906, 0, 4)
      Dim car2 As New Automobile("Ford", "Model T", 1909, 2, 4)
      ' Define a resource file named CarResources.resx.
      Using resx As New ResXResourceWriter(".\CarResources.resx")
         resx.AddResource("Title", "Classic American Cars")
         resx.AddResource("HeaderString1", "Make")
         resx.AddResource("HeaderString2", "Model")
         resx.AddResource("HeaderString3", "Year")
         resx.AddResource("HeaderString4", "Doors")
         resx.AddResource("HeaderString5", "Cylinders")
         resx.AddResource("Information", SystemIcons.Information) 
         resx.AddResource("EarlyAuto1", car1)
         resx.AddResource("EarlyAuto2", car2)  
      End Using
   End Sub
End Module

이 예제에서 정의되고 인스턴스화된 Automobile 클래스는 SerializableAttribute 특성으로 태그가 지정됩니다.Note that the Automobile class, which is defined and instantiated in the example, is tagged with the SerializableAttribute attribute.

설명

Generate를 호출할 때까지 리소스가 기록 되지 않습니다.The resource is not written until Generate is called.

AddResource(ResXDataNode)

작성할 리소스 목록에 ResXDataNode 개체에 지정된 명명된 리소스를 추가합니다.Adds a named resource specified in a ResXDataNode object to the list of resources to write.

public:
 void AddResource(System::Resources::ResXDataNode ^ node);
public void AddResource (System.Resources.ResXDataNode node);
member this.AddResource : System.Resources.ResXDataNode -> unit
Public Sub AddResource (node As ResXDataNode)

매개 변수

node
ResXDataNode

리소스 이름/값 쌍이 들어 있는 ResXDataNode 개체입니다.A ResXDataNode object that contains a resource name/value pair.

AddResource(String, Byte[])

기록할 리소스 목록에 바이트 배열로 지정된 명명된 리소스를 추가합니다.Adds a named resource specified as a byte array to the list of resources to write.

public:
 virtual void AddResource(System::String ^ name, cli::array <System::Byte> ^ value);
public void AddResource (string name, byte[] value);
abstract member AddResource : string * byte[] -> unit
override this.AddResource : string * byte[] -> unit
Public Sub AddResource (name As String, value As Byte())

매개 변수

name
String

리소스의 이름입니다.The name of the resource.

value
Byte[]

부호 없는 8비트 정수 배열로 추가될 리소스의 값입니다.The value of the resource to add as an 8-bit unsigned integer array.

구현

설명

Generate를 호출할 때까지 리소스가 기록 되지 않습니다.The resource is not written until Generate is called.

리소스는 직렬화 되 고 이진 형식으로 저장 합니다.The resource is serialized and stored in a binary format.

적용 대상