ResXDataNode ResXDataNode ResXDataNode ResXDataNode Class

定義

表示 XML 資源檔 (.resx) 中的項目。Represents an element in an XML resource (.resx) file.

public ref class ResXDataNode sealed : System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class ResXDataNode : System.Runtime.Serialization.ISerializable
type ResXDataNode = class
    interface ISerializable
Public NotInheritable Class ResXDataNode
Implements ISerializable
繼承
ResXDataNodeResXDataNodeResXDataNodeResXDataNode
屬性
實作

範例

下列範例ResXResourceReader.GetEnumerator 會使用IDictionaryEnumerator方法來取得用來列舉 .resx 檔案中之物件的物件。ResXDataNodeThe following example uses the ResXResourceReader.GetEnumerator method to obtain an IDictionaryEnumerator object that is used to enumerate the ResXDataNode objects in a .resx file. 這個範例包含一個CreateResourceFile常式, 它會建立必要的 XML 資源檔。The example includes a CreateResourceFile routine that creates the necessary XML resource file.

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

public class Example
{
   private const string resxFilename = @".\CountryHeaders.resx";
    
   public static void Main()
   {
      // Create a resource file to read.
      CreateResourceFile();
      
      // Enumerate the resources in the file.
      ResXResourceReader rr = new ResXResourceReader(resxFilename);
      rr.UseResXDataNodes = true;
      IDictionaryEnumerator dict = rr.GetEnumerator();
      while (dict.MoveNext()) {
         ResXDataNode node = (ResXDataNode) dict.Value;
         Console.WriteLine("{0,-20} {1,-20} {2}", 
                           node.Name + ":", 
                           node.GetValue((ITypeResolutionService) null), 
                           ! String.IsNullOrEmpty(node.Comment) ? "// " + node.Comment : "");
      }
   }

   private static void CreateResourceFile()
   {
      ResXResourceWriter rw = new ResXResourceWriter(resxFilename);
      string[] resNames = {"Country", "Population", "Area", 
                           "Capital", "LCity" };
      string[] columnHeaders = { "Country Name", "Population (2010}", 
                                 "Area", "Capital", "Largest City" };
      string[] comments = { "The localized country name", "Estimated population, 2010", 
                            "The area in square miles", "Capital city or chief administrative center", 
                            "The largest city based on 2010 data" };
      rw.AddResource("Title", "Country Information");
      rw.AddResource("nColumns", resNames.Length);
      for (int ctr = 0; ctr < resNames.Length; ctr++) {
         ResXDataNode node = new ResXDataNode(resNames[ctr], columnHeaders[ctr]);
         node.Comment = comments[ctr];
         rw.AddResource(node);
      }
      rw.Generate();
      rw.Close();
   }
}
// The example displays the following output:
//    Title:               Country Information
//    nColumns:            5
//    Country:             Country Name         // The localized country name
//    Population:          Population (2010}    // Estimated population, 2010
//    Area:                Area                 // The area in square miles
//    Capital:             Capital              // Capital city or chief administrative center
//    LCity:               Largest City         // The largest city based on 2010 data
Imports System.Collections
Imports System.ComponentModel.Design
Imports System.Resources

Module Example
   Private Const resxFilename As String = ".\CountryHeaders.resx"
     
   Public Sub Main()
      ' Create a resource file to read.
      CreateResourceFile()
      
      ' Enumerate the resources in the file.
      Dim rr As New ResXResourceReader(resxFilename)
      rr.UseResXDataNodes = True
      Dim dict As IDictionaryEnumerator = rr.GetEnumerator()
      Do While dict.MoveNext()
         Dim node As ResXDataNode = DirectCast(dict.Value, ResXDataNode)
         Console.WriteLine("{0,-20} {1,-20} {2}", 
                           node.Name + ":", 
                           node.GetValue(CType(Nothing, ITypeResolutionService)), 
                           If(Not String.IsNullOrEmpty(node.Comment), "// " + node.Comment, ""))
      Loop
   End Sub
   
   Private Sub CreateResourceFile()
      Dim rw As New ResxResourceWriter(resxFilename)
      Dim resNames() As String = {"Country", "Population", "Area", 
                                  "Capital", "LCity" }
      Dim columnHeaders() As String = { "Country Name", "Population (2010}", 
                                        "Area", "Capital", "Largest City" }
      Dim comments() As String = { "The localized country name", "Estimated population, 2010", 
                                   "The area in square miles", "Capital city or chief administrative center", 
                                   "The largest city based on 2010 data" }
      rw.AddResource("Title", "Country Information")
      rw.AddResource("nColumns", resNames.Length)
      For ctr As Integer = 0 To resNames.Length - 1
         Dim node As New ResXDataNode(resNames(ctr), columnHeaders(ctr))
         node.Comment = comments(ctr)
         rw.AddResource(node)
      Next
      rw.Generate()
      rw.Close()
   End Sub
End Module
' The example displays the following output:
'    Title:               Country Information
'    nColumns:            5
'    Country:             Country Name         // The localized country name
'    Population:          Population (2010}    // Estimated population, 2010
'    Area:                Area                 // The area in square miles
'    Capital:             Capital              // Capital city or chief administrative center
'    LCity:               Largest City         // The largest city based on 2010 data

因為屬性為true ResXDataNode , 所以屬性的值是物件, 而不是資源值。 IDictionaryEnumerator.Value UseResXDataNodesBecause the UseResXDataNodes property is true, the value of the IDictionaryEnumerator.Value property is a ResXDataNode object rather than the resource value. 這會讓資源專案的批註可從ResXDataNode.Comment屬性取得。This makes a resource item's comment available from the ResXDataNode.Comment property.

備註

ResXDataNode類別支援在資源檔中表示豐富的資料類型。The ResXDataNode class supports the representation of rich data types within a resource file. 只要物件支援序列化和類型編輯器, 它就可以支援資源檔中任何物件的儲存。It can support the storage of any object in a resource file, so long as the object supports serialization and type editors.

您可以藉由ResXDataNode呼叫其中一個多載類別的函式來建立物件。You can create a ResXDataNode object by calling one of its overloaded class constructors. 接著, 您可以藉由呼叫ResXResourceWriter.AddResource方法, 將資源專案或元素新增至資源檔。You can then add the resource item or element to a resource file by calling the ResXResourceWriter.AddResource method.

若要取出現有ResXDataNode的物件, 您必須藉ResXDataNode由具現化ResXResourceReader物件、將ResXResourceReader.UseResXDataNodes屬性ResXResourceReader.GetEnumerator設定為true, 以及呼叫方法, 來列舉 XML 資源檔中的物件。取得列舉值。To retrieve an existing ResXDataNode object, you must enumerate the ResXDataNode objects in an XML resource file by instantiating a ResXResourceReader object, setting the ResXResourceReader.UseResXDataNodes property to true, and calling the ResXResourceReader.GetEnumerator method to get an enumerator. 這個範例將提供說明。The example provides an illustration.

建構函式

ResXDataNode(String, Object) ResXDataNode(String, Object) ResXDataNode(String, Object) ResXDataNode(String, Object)

初始化 ResXDataNode 類別的新執行個體。Initializes a new instance of the ResXDataNode class.

ResXDataNode(String, Object, Func<Type,String>) ResXDataNode(String, Object, Func<Type,String>) ResXDataNode(String, Object, Func<Type,String>) ResXDataNode(String, Object, Func<Type,String>)

初始化 ResXDataNode 類別的新執行個體。Initializes a new instance of the ResXDataNode class.

ResXDataNode(String, ResXFileRef) ResXDataNode(String, ResXFileRef) ResXDataNode(String, ResXFileRef) ResXDataNode(String, ResXFileRef)

使用資源檔的參考,初始化 ResXDataNode 類別的新執行個體。Initializes a new instance of the ResXDataNode class with a reference to a resource file.

ResXDataNode(String, ResXFileRef, Func<Type,String>) ResXDataNode(String, ResXFileRef, Func<Type,String>) ResXDataNode(String, ResXFileRef, Func<Type,String>) ResXDataNode(String, ResXFileRef, Func<Type,String>)

使用資源檔的參考,初始化 ResXDataNode 類別的新執行個體。Initializes a new instance of the ResXDataNode class with a reference to a resource file.

屬性

Comment Comment Comment Comment

取得或設定有關這個資源的任意註解。Gets or sets an arbitrary comment regarding this resource.

FileRef FileRef FileRef FileRef

取得這個資源的檔案參考。Gets the file reference for this resource.

Name Name Name Name

取得或設定這個資源的名稱。Gets or sets the name of this resource.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetNodePosition() GetNodePosition() GetNodePosition() GetNodePosition()

擷取資源在資源檔中的位置。Retrieves the position of the resource in the resource file.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
GetValue(AssemblyName[]) GetValue(AssemblyName[]) GetValue(AssemblyName[]) GetValue(AssemblyName[])

藉由搜尋指定的組件,擷取這個節點所儲存的物件。Retrieves the object that is stored by this node by searching the specified assemblies.

GetValue(ITypeResolutionService) GetValue(ITypeResolutionService) GetValue(ITypeResolutionService) GetValue(ITypeResolutionService)

藉由使用型別解析服務,擷取這個節點所儲存的物件。Retrieves the object that is stored by this node by using the specified type resolution service.

GetValueTypeName(AssemblyName[]) GetValueTypeName(AssemblyName[]) GetValueTypeName(AssemblyName[]) GetValueTypeName(AssemblyName[])

藉由檢查指定的組件,擷取值的型別名稱。Retrieves the type name for the value by examining the specified assemblies.

GetValueTypeName(ITypeResolutionService) GetValueTypeName(ITypeResolutionService) GetValueTypeName(ITypeResolutionService) GetValueTypeName(ITypeResolutionService)

藉由使用指定的型別解析服務,擷取值的型別名稱。Retrieves the type name for the value by using the specified type resolution service.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

將序列化目標物件所需要的資料填入 SerializationInfo 物件中。Populates a SerializationInfo object with the data needed to serialize the target object.

安全性

LinkDemand
針對立即呼叫者的完全信任的。for full trust for the immediate caller. 部分信任的程式碼無法使用此類型。This type cannot be used by partially trusted code.

適用於

另請參閱