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

发布于 2024-12-16 01:32:40 字数 844 浏览 3 评论 0原文

我有一个单独的应用程序(用于拼写检查我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦爱 2024-12-23 01:32:40

是的。在 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);
    }
}

Yes. Setting UseResXDataNodes on ResXResourceReader will cause the dictionary values to be a ResXDataNode instead of the actual value, which you can use to determine if it is a file or not. Something like this:

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文