本文整理汇总了C#中System.Resources.ResXResourceReader.UseResXDataNodes属性的典型用法代码示例。如果您正苦于以下问题:C# ResXResourceReader.UseResXDataNodes属性的具体用法?C# ResXResourceReader.UseResXDataNodes怎么用?C# ResXResourceReader.UseResXDataNodes使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Resources.ResXResourceReader
的用法示例。
在下文中一共展示了ResXResourceReader.UseResXDataNodes属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Collections;
using System.Resources;
using System.ComponentModel.Design;
namespace UseDataNodesExample
{
public class Program
{
public static void Main()
{
Console.WriteLine("\nEnumerating as data items...");
EnumResourceItems("Resource1.resx", false);
Console.WriteLine("\nEnumerating as data nodes...");
EnumResourceItems("Resource1.resx", true);
}
public static void EnumResourceItems(string resxFile, bool useDataNodes)
{
using (ResXResourceReader reader = new ResXResourceReader(resxFile))
{
reader.UseResXDataNodes = useDataNodes;
// Enumerate using IEnumerable.GetEnumerator().
Console.WriteLine("\n Default enumerator:");
foreach (DictionaryEntry entry in reader)
{
ShowResourceItem(entry, useDataNodes);
}
// Enumerate using GetMetadataEnumerator()
IDictionaryEnumerator metadataEnumerator = reader.GetMetadataEnumerator();
Console.WriteLine("\n MetadataEnumerator:");
while (metadataEnumerator.MoveNext())
{
ShowResourceItem(metadataEnumerator.Entry, useDataNodes);
}
// Enumerate using GetEnumerator()
IDictionaryEnumerator enumerator = reader.GetEnumerator();
Console.WriteLine("\n Enumerator:");
while (enumerator.MoveNext())
{
ShowResourceItem(enumerator.Entry, useDataNodes);
}
}
}
public static void ShowResourceItem(DictionaryEntry entry, bool isDataNode)
{
// Use a null type resolver.
ITypeResolutionService typeres = null;
ResXDataNode dnode;
if (isDataNode)
{
// Display from node info.
dnode = (ResXDataNode)entry.Value;
Console.WriteLine(" {0}={1}", dnode.Name, dnode.GetValue(typeres));
}
else
{
// Display as DictionaryEntry info.
Console.WriteLine(" {0}={1}", entry.Key, entry.Value);
}
}
}
}
输出:
Enumerating as data items... Default enumerator: DataSample=Sample DATA value MetadataEnumerator: MetadataSample=Sample METADATA value Enumerator: DataSample=Sample DATA value Enumerating as data nodes... Default enumerator: DataSample=Sample DATA value MetadataSample=Sample METADATA value MetadataEnumerator: Enumerator: DataSample=Sample DATA value MetadataSample=Sample METADATA value