ResXDataNode クラス

定義

XML リソース (.resx) ファイル内の要素を表します。

public ref class ResXDataNode sealed : System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class ResXDataNode : System.Runtime.Serialization.ISerializable
public sealed class ResXDataNode : System.Runtime.Serialization.ISerializable
[<System.Serializable>]
type ResXDataNode = class
    interface ISerializable
type ResXDataNode = class
    interface ISerializable
Public 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

プロパティは UseResXDataNodestrueであるため、プロパティの IDictionaryEnumerator.Value 値は ResXDataNode リソース値ではなくオブジェクトです。 これにより、 プロパティからリソース アイテムのコメントを ResXDataNode.Comment 使用できるようになります。

注釈

重要

このクラスのメソッドを信頼されていないデータを指定して呼び出すことには、セキュリティ上のリスクが伴います。 このクラスのメソッドの呼び出しは、信頼されたデータだけを指定して実行してください。 詳細については、「 すべての入力を検証する」を参照してください。

クラスは ResXDataNode 、リソース ファイル内のリッチ データ型の表現をサポートします。 オブジェクトがシリアル化エディターと型エディターをサポートしている限り、リソース ファイル内の任意のオブジェクトのストレージをサポートできます。

オーバーロードされたクラス コンストラクターのいずれかを呼び出すことで、オブジェクトを作成 ResXDataNode できます。 その後、 メソッドを呼び出して、リソース アイテムまたは要素をリソース ファイルに ResXResourceWriter.AddResource 追加できます。

既存ResXDataNodeのオブジェクトを取得するには、オブジェクトをResXDataNodeインスタンス化し、 プロパティを にtrue設定ResXResourceReader.UseResXDataNodesし、 メソッドを呼び出ResXResourceReader.GetEnumeratorして列挙子をResXResourceReader取得することで、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 オブジェクトに、対象オブジェクトをシリアル化するために必要なデータを設定します。

適用対象

こちらもご覧ください