ResXDataNode Klasa

Definicja

Reprezentuje element w pliku zasobu 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
Dziedziczenie
ResXDataNode
Atrybuty
Implementuje

Przykłady

W poniższym przykładzie ResXResourceReader.GetEnumerator użyto metody w celu uzyskania IDictionaryEnumerator obiektu używanego do wyliczania ResXDataNode obiektów w pliku resx. W tym przykładzie przedstawiono procedurę CreateResourceFile , która tworzy niezbędny plik zasobów 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 Ponieważ właściwość to true, wartość IDictionaryEnumerator.Value właściwości jest obiektemResXDataNode, a nie wartością zasobu. Spowoduje to udostępnienie komentarza elementu zasobu z ResXDataNode.Comment właściwości.

Uwagi

Ważne

Wywoływanie metod z tej klasy z niezaufanymi danymi jest zagrożeniem bezpieczeństwa. Wywołaj metody z tej klasy tylko z zaufanymi danymi. Aby uzyskać więcej informacji, zobacz Weryfikowanie wszystkich danych wejściowych.

Klasa ResXDataNode obsługuje reprezentację zaawansowanych typów danych w pliku zasobów. Może obsługiwać magazyn dowolnego obiektu w pliku zasobów, tak długo, jak obiekt obsługuje serializacji i edytory typów.

Obiekt można utworzyć ResXDataNode , wywołując jeden z jego przeciążonych konstruktorów klas. Następnie można dodać element lub element zasobu do pliku zasobu, wywołując metodę ResXResourceWriter.AddResource .

Aby pobrać istniejący ResXDataNode obiekt, należy wyliczyć ResXDataNode obiekty w pliku zasobów XML, tworząc wystąpienie obiektu, ustawiając ResXResourceReaderResXResourceReader.UseResXDataNodes właściwość na true, i wywołując metodę w celu pobrania modułu ResXResourceReader.GetEnumerator wyliczającego. Przykład stanowi ilustrację.

Konstruktory

ResXDataNode(String, Object)

Inicjuje nowe wystąpienie klasy ResXDataNode.

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

Inicjuje nowe wystąpienie klasy ResXDataNode.

ResXDataNode(String, ResXFileRef)

Inicjuje ResXDataNode nowe wystąpienie klasy z odwołaniem do pliku zasobu.

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

Inicjuje ResXDataNode nowe wystąpienie klasy z odwołaniem do pliku zasobu.

Właściwości

Comment

Pobiera lub ustawia dowolny komentarz dotyczący tego zasobu.

FileRef

Pobiera odwołanie do pliku dla tego zasobu.

Name

Pobiera lub ustawia nazwę tego zasobu.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetNodePosition()

Pobiera pozycję zasobu w pliku zasobu.

GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
GetValue(AssemblyName[])

Pobiera obiekt przechowywany przez ten węzeł, wyszukując określone zestawy.

GetValue(ITypeResolutionService)

Pobiera obiekt przechowywany przez ten węzeł przy użyciu określonej usługi rozpoznawania typów.

GetValueTypeName(AssemblyName[])

Pobiera nazwę typu dla wartości, sprawdzając określone zestawy.

GetValueTypeName(ITypeResolutionService)

Pobiera nazwę typu dla wartości przy użyciu określonej usługi rozpoznawania typów.

MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

SerializationInfo Wypełnia obiekt danymi wymaganymi do serializacji obiektu docelowego.

Dotyczy

Zobacz też