使用 ResXResourceReader 时如何判断资源是嵌入文件还是嵌入字符串
我有一个单独的应用程序(用于拼写检查我的 .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;
}
I have a separate application (that is for the purpose of spell checking my .resx files) that runs as a pre-build event. However, if the .resx file contains a text file (xml for example) my application will load the file and attempt to spell check it. This is not really what I want it to do. Is there a way to tell from the ResXResourceReader if the resource loaded is actually a file?
Code sample looks like this:
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。在
ResXResourceReader
上设置UseResXDataNodes
将导致字典值成为ResXDataNode
而不是实际值,您可以使用它来确定它是否是一个文件与否。像这样的东西:Yes. Setting
UseResXDataNodes
onResXResourceReader
will cause the dictionary values to be aResXDataNode
instead of the actual value, which you can use to determine if it is a file or not. Something like this: