我有一个单独的应用程序(用于拼写检查我的.resx文件)作为预构建事件运行.但是,如果.resx文件包含文本文件(例如xml),我的应用程序将加载该文件并尝试拼写检查它.这不是我想要的.有没有办法告诉ResXResourceReader,如果加载的资源实际上是一个文件?
代码示例如下所示:
ResXResourceReader reader = new ResXResourceReader(filename);
ResourceSet resourceset = new ResourceSet(reader);
Dictionary<DictionaryEntry, object> newvalues = new Dictionary<DictionaryEntry, object>();
foreach (DictionaryEntry entry in resourceset)
{
//Figure out in this 'if' if it is an embedded file and should be ignored.
if (entry.Key.ToString().StartsWith(">>") || !(entry.Value is string) || string.Compare((string)entry.Value, "---") == 0)
continue;
}
Run Code Online (Sandbox Code Playgroud)
是.设置UseResXDataNodes
为ResXResourceReader
将导致字典值为ResXDataNode
而不是实际值,您可以使用它来确定它是否是文件.像这样的东西:
var rsxr = new ResXResourceReader("Test.resx");
rsxr.UseResXDataNodes = true;
foreach (DictionaryEntry de in rsxr)
{
var node = (ResXDataNode)de.Value;
//FileRef is null if it is not a file reference.
if (node.FileRef == null)
{
//Spell check your value.
var value = node.GetValue((ITypeResolutionService) null);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7492 次 |
最近记录: |