When using ResXResourceReader, how to determine if a resource is an inline file or is an inline string

I have a separate application (that is, to check the spelling of my .resx files) that fires as a pre-build event. However, if the .resx file contains a text file (e.g. xml), my application will download the file and try to check it. In fact, I do not want to do this. Is there any way to tell from ResXResourceReader if the loaded resource is actually a file?

Sample code is as follows:

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; } 
+6
source share
1 answer

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

 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); } } 
+6
source

Source: https://habr.com/ru/post/901659/


All Articles