ResXResourceReader.GetEnumerator Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Retourneert een enumerator voor het huidige ResXResourceReader object.
public:
virtual System::Collections::IDictionaryEnumerator ^ GetEnumerator();
public System.Collections.IDictionaryEnumerator GetEnumerator();
abstract member GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
override this.GetEnumerator : unit -> System.Collections.IDictionaryEnumerator
Public Function GetEnumerator () As IDictionaryEnumerator
Retouren
Een enumerator voor het huidige ResourceReader object.
Implementeringen
Voorbeelden
In het volgende voorbeeld wordt de GetEnumerator methode gebruikt om een IDictionaryEnumerator object te verkrijgen dat wordt gebruikt om de resources in een RESX-bestand op te sommen. Het voorbeeld bevat een CreateResourceFile routine waarmee het benodigde resourcebestand wordt gemaakt.
using System;
using System.Collections;
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);
IDictionaryEnumerator dict = rr.GetEnumerator();
while (dict.MoveNext())
Console.WriteLine("{0}: {1}", dict.Key, dict.Value);
}
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", "",
"The area in square miles", "",
"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
// Population: Population (2010}
// Area: Area
// Capital: Capital
// LCity: Largest City
Imports System.Collections
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)
Dim dict As IDictionaryEnumerator = rr.GetEnumerator()
Do While dict.MoveNext()
Console.WriteLine("{0}: {1}", dict.Key, dict.Value)
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", "",
"The area in square miles", "",
"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
' Population: Population (2010}
' Area: Area
' Capital: Capital
' LCity: Largest City
Opmerkingen
Met GetEnumerator de methode worden de naam-/waardeparen opgehaald in de XML-resourcestroom (.resx) of tekenreeks die is gekoppeld aan het huidige ResXResourceReader object. Als de UseResXDataNodes eigenschap echter is ingesteld true voordat u aanroept GetEnumerator, worden de resource-items opgehaald als ResXDataNode objecten. In dit geval worden alle resourceknooppunten geretourneerd, ongeacht het type.