Aracılığıyla paylaş


ResXResourceWriter.AddResource Yöntem

Tanım

Yazacak kaynaklar listesine bir kaynak ekler.

Aşırı Yüklemeler

AddResource(String, Object)

Yazacak kaynaklar listesine nesne olarak belirtilen adlandırılmış bir kaynağı ekler.

AddResource(String, String)

Kaynaklara bir dize kaynağı ekler.

AddResource(ResXDataNode)

Nesnede ResXDataNode belirtilen adlandırılmış kaynağı yazacak kaynak listesine ekler.

AddResource(String, Byte[])

Yazacak kaynaklar listesine bayt dizisi olarak belirtilen adlandırılmış bir kaynağı ekler.

AddResource(String, Object)

Yazacak kaynaklar listesine nesne olarak belirtilen adlandırılmış bir kaynağı ekler.

public:
 virtual void AddResource(System::String ^ name, System::Object ^ value);
public void AddResource (string name, 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)

Parametreler

name
String

Kaynağın adı.

value
Object

Kaynağın değeri.

Uygulamalar

Örnekler

Aşağıdaki örnek, altı dize, bir simge ve iki uygulama tanımlı nesne (iki Automobile nesne) depolayan adlı CarResources.resx bir .resx dosyası oluşturur. Simgeyi ve nesneleri depolamak Automobile için yöntemini çağırır AddResource(String, Object) . Automobile Örnekte tanımlanan ve örneği oluşturulmuş sınıfın özniteliğiyle SerializableAttribute etiketlendiğini unutmayın.

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

Açıklamalar

Kaynak çağrılana kadar Generate yazılmaz. Eklenen kaynağın seri hale getirilebilir olması gerekir.

Eklenen kaynak bir dizeyse, dize olarak yazılır; aksi takdirde, kaynak seri hale getirilir ve ikili biçimde depolanır.

Şunlara uygulanır

AddResource(String, String)

Kaynaklara bir dize kaynağı ekler.

public:
 virtual void AddResource(System::String ^ name, System::String ^ value);
public void AddResource (string name, 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)

Parametreler

name
String

Kaynağın adı.

value
String

Kaynağın değeri.

Uygulamalar

Örnekler

Aşağıdaki örnek, altı dize, bir simge ve iki uygulama tanımlı nesne (iki Automobile nesne) depolayan adlı CarResources.resx bir .resx dosyası oluşturur. Dizeleri depolamak için yöntemini çağırır AddResource(String, String) .

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 Örnekte tanımlanan ve örneği oluşturulmuş sınıfın özniteliğiyle SerializableAttribute etiketlendiğini unutmayın.

Açıklamalar

Kaynak çağrılana kadar Generate yazılmaz.

Şunlara uygulanır

AddResource(ResXDataNode)

Nesnede ResXDataNode belirtilen adlandırılmış kaynağı yazacak kaynak listesine ekler.

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)

Parametreler

node
ResXDataNode

Kaynak ResXDataNode adı/değer çifti içeren bir nesne.

Şunlara uygulanır

AddResource(String, Byte[])

Yazacak kaynaklar listesine bayt dizisi olarak belirtilen adlandırılmış bir kaynağı ekler.

public:
 virtual void AddResource(System::String ^ name, cli::array <System::Byte> ^ value);
public void AddResource (string name, 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())

Parametreler

name
String

Kaynağın adı.

value
Byte[]

8 bit işaretsiz tamsayı dizisi olarak eklenecek kaynağın değeri.

Uygulamalar

Açıklamalar

Kaynak çağrılana kadar Generate yazılmaz.

Kaynak seri hale getirilir ve ikili biçimde depolanır.

Şunlara uygulanır