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

C# 使用ResXResourceReader时,如何判断资源是嵌入式文件还是嵌入式字符串,c#,resx,C#,Resx,我有一个单独的应用程序(用于拼写检查我的.resx文件),它作为预构建事件运行。但是,如果.resx文件包含文本文件(例如xml),我的应用程序将加载该文件并尝试对其进行拼写检查。这不是我想要它做的。有没有办法从ResXResourceReader判断加载的资源是否是一个文件 代码示例如下所示: ResXResourceReader reader = new ResXResourceReader(filename); Resourc

我有一个单独的应用程序(用于拼写检查我的.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;
                 }
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);
    }
}
ResXResourceReader=新的ResXResourceReader(文件名);
ResourceSet ResourceSet=新资源集(读卡器);
Dictionary newvalues=newdictionary();
foreach(资源集中的DictionaryEntry条目)
{
//在这个“如果”中找出它是否是一个嵌入文件,并且应该被忽略。
if(entry.Key.ToString().StartsWith(“>>”)| | |!(entry.Value为string)| | string.Compare((string)entry.Value,“--”)==0)
继续;
}

是。在
ResXResourceReader
上设置
UseResXDataNodes
将导致字典值为
ResXDataNode
而不是实际值,您可以使用实际值确定它是否为文件。大概是这样的:

                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;
                 }
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);
    }
}