ResXDataNode 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 XML 资源 (.resx) 文件中的元素。
public ref class ResXDataNode sealed : System::Runtime::Serialization::ISerializable[System.Serializable]
public sealed class ResXDataNode : System.Runtime.Serialization.ISerializablepublic sealed class ResXDataNode : System.Runtime.Serialization.ISerializable[<System.Serializable>]
type ResXDataNode = class
    interface ISerializabletype ResXDataNode = class
    interface ISerializablePublic NotInheritable Class ResXDataNode
Implements ISerializable- 继承
- 
				ResXDataNode
- 属性
- 实现
示例
以下示例使用 ResXResourceReader.GetEnumerator 方法获取 IDictionaryEnumerator 对象,该对象用于枚举 .resx 文件中的对象 ResXDataNode 。 该示例包含一个 CreateResourceFile 例程,用于创建必要的 XML 资源文件。
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
              UseResXDataNodes因为 属性是 true,属性的值IDictionaryEnumerator.Value是 对象ResXDataNode而不是资源值。 这使资源项的注释可从 ResXDataNode.Comment 属性获得。
注解
重要
使用不受信任的数据调用此类中的方法存在安全风险。 仅使用受信任的数据调用此类中的方法。 有关详细信息,请参阅 验证所有输入。
类 ResXDataNode 支持资源文件中丰富数据类型的表示形式。 只要对象支持序列化和类型编辑器,它就可以支持在资源文件中存储任何对象。
可以通过调用对象的重载类构造函数之一来创建 ResXDataNode 对象。 然后,可以通过调用 ResXResourceWriter.AddResource 方法将资源项或元素添加到资源文件。
若要检索现有ResXDataNode对象,必须通过实例化 ResXResourceReader 对象、将 ResXResourceReader.UseResXDataNodes 属性设置为 true并调用 ResXResourceReader.GetEnumerator 方法来获取枚举器来枚举 ResXDataNode XML 资源文件中的对象。 说明如示例所示。
构造函数
| ResXDataNode(String, Object) | 初始化 ResXDataNode 类的新实例。 | 
| ResXDataNode(String, Object, Func<Type,String>) | 初始化 ResXDataNode 类的新实例。 | 
| ResXDataNode(String, ResXFileRef) | 使用对资源文件的引用初始化 ResXDataNode 类的新实例。 | 
| ResXDataNode(String, ResXFileRef, Func<Type,String>) | 使用对资源文件的引用初始化 ResXDataNode 类的新实例。 | 
属性
| Comment | 获取或设置关于此资源的任意注释。 | 
| FileRef | 获取此资源的文件引用。 | 
| Name | 获取或设置此资源的名称。 | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetNodePosition() | 检索资源在资源文件中的位置。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| GetValue(AssemblyName[]) | 通过搜索指定程序集检索由此节点存储的对象。 | 
| GetValue(ITypeResolutionService) | 通过使用指定的类型解决方案服务检索由此节点存储的对象。 | 
| GetValueTypeName(AssemblyName[]) | 通过检查指定的程序集检索值的类型名称。 | 
| GetValueTypeName(ITypeResolutionService) | 通过使用指定的类型解决方案服务检索值的类型名称。 | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
显式接口实现
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) | 使用序列化目标对象所需的数据填充 SerializationInfo 对象。 |