gpt4 book ai didi

c# - 使用 ResXResourceReader 时如何判断资源是嵌入文件还是嵌入字符串

转载 作者:太空狗 更新时间:2023-10-29 21:35:53 27 4
gpt4 key购买 nike

我有一个作为预构建事件运行的单独应用程序(用于拼写检查我的 .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;
}

最佳答案

是的。在 ResXResourceReader 上设置 UseResXDataNodes 将导致字典值为 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);
}
}

关于c# - 使用 ResXResourceReader 时如何判断资源是嵌入文件还是嵌入字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8158544/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com