【问题标题】:When using the ResXResourceReader how can tell if the resource is an embedded file or if it is an embedded string使用 ResXResourceReader 时如何判断资源是嵌入式文件还是嵌入式字符串
【发布时间】:2011-11-16 20:56:35
【问题描述】:

我有一个单独的应用程序(用于对我的 .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;
                 }

【问题讨论】:

    标签: c# resx


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-10-30
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      相关资源
      最近更新 更多