ResXResourceWriter Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Writes resources in an XML resource (.resx) file or an output stream.

Namespace:   System.Resources
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

System.Object
  System.Resources.ResXResourceWriter

[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
public class ResXResourceWriter : IResourceWriter, IDisposable

NameDescription
System_CAPS_pubmethodResXResourceWriter(Stream)

Initializes a new instance of the ResXResourceWriter class that writes the resources to the specified stream object.

System_CAPS_pubmethodResXResourceWriter(Stream, Func<Type, String>)

Initializes a new instance of the ResXResourceWriter class that writes the resources to a specified stream object and sets a converter delegate. This delegate enables resource assemblies to be written that target versions of the .NET Framework before the .NET Framework 4 by using qualified assembly names. 

System_CAPS_pubmethodResXResourceWriter(String)

Initializes a new instance of the ResXResourceWriter class that writes the resources to the specified file.

System_CAPS_pubmethodResXResourceWriter(String, Func<Type, String>)

Initializes a new instance of the ResXResourceWriter class that writes the resources to a specified file and sets a delegate that enables resource assemblies to be written that target versions of the .NET Framework before the .NET Framework 4 by using qualified assembly names. 

System_CAPS_pubmethodResXResourceWriter(TextWriter)

Initializes a new instance of the ResXResourceWriter class that writes to the specified TextWriter object.

System_CAPS_pubmethodResXResourceWriter(TextWriter, Func<Type, String>)

Initializes a new instance of the ResXResourceWriter class that writes the resources to a specified TextWriter object and sets a delegate that enables resource assemblies to be written that target versions of the .NET Framework before the .NET Framework 4 by using qualified assembly names.

NameDescription
System_CAPS_pubpropertyBasePath

Gets or sets the base path for the relative file path specified in a ResXFileRef object.

NameDescription
System_CAPS_pubmethodAddAlias(String, AssemblyName)

Adds the specified alias to a list of aliases.

System_CAPS_pubmethodAddMetadata(String, Byte[])

Adds a design-time property whose value is specifed as a byte array to the list of resources to write.

System_CAPS_pubmethodAddMetadata(String, Object)

Adds a design-time property whose value is specified as an object to the list of resources to write.

System_CAPS_pubmethodAddMetadata(String, String)

Adds a design-time property whose value is specified as a string to the list of resources to write.

System_CAPS_pubmethodAddResource(ResXDataNode)

Adds a named resource specified in a ResXDataNode object to the list of resources to write.

System_CAPS_pubmethodAddResource(String, Byte[])

Adds a named resource specified as a byte array to the list of resources to write.

System_CAPS_pubmethodAddResource(String, Object)

Adds a named resource specified as an object to the list of resources to write.

System_CAPS_pubmethodAddResource(String, String)

Adds a string resource to the resources.

System_CAPS_pubmethodClose()

Releases all resources used by the ResXResourceWriter.

System_CAPS_pubmethodDispose()

Releases all resources used by the ResXResourceWriter.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the ResXResourceWriter and optionally releases the managed resources.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

This member overrides the Finalize method. (Overrides Object.Finalize().)

System_CAPS_pubmethodGenerate()

Writes all resources added by the AddResource method to the output file or stream.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticBinSerializedObjectMimeType

This API supports the product infrastructure and is not intended to be used directly from your code. Specifies the default content type for a binary object. This field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticByteArraySerializedObjectMimeType

This API supports the product infrastructure and is not intended to be used directly from your code. Specifies the default content type for a byte array object. This field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticDefaultSerializedObjectMimeType

This API supports the product infrastructure and is not intended to be used directly from your code. Specifies the default content type for an object. This field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticResMimeType

This API supports the product infrastructure and is not intended to be used directly from your code. Specifies the content type of an XML resource. This field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticResourceSchema

This API supports the product infrastructure and is not intended to be used directly from your code. Specifies the schema to use in writing the XML file. This field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticSoapSerializedObjectMimeType

This API supports the product infrastructure and is not intended to be used directly from your code. Specifies the content type for a SOAP object. This field is read-only.

System_CAPS_pubfieldSystem_CAPS_staticVersion

Specifies the version of the schema that the XML output conforms to. This field is read-only.

The ResXResourceWriter writes resources in XML format. To write a binary resource file, use ResourceWriter.

Resources are specified as name/value pairs using the AddResource method. Resource names are case-sensitive when used for lookups; but to more easily support authoring tools and help eliminate bugs, ResXResourceWriter does not allow a.resx file to have names that vary only by case.

To create a.resx file, create a ResXResourceWriter with a unique file name, call AddResource at least once, call Generate to write the resources file to disk, and then call Close to close the file. Calling Close will implicitly Generate the file if required.

The resources are not necessarily written in the same order they were added.

For more information on the format of a.resx file, see Working with .resx Files Programmatically.

System_CAPS_noteNote

This class contains a link demand and an inheritance demand at the class level that applies to all members. A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission.

The following example creates a .resx file named CarResources.resx that stores six strings, an icon, and two application-defined objects (two Automobile objects). 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);  
      }
   }
}

SecurityAction.LinkDemand

for full trust for the immediate caller. This member cannot be used by partially trusted code.

SecurityAction.InheritanceDemand

for full trust for inheritors. This member cannot be inherited by partially trusted code.

.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: