謝謝@Teudimundo。我修改該鏈接的片段如下:
var asm = Assembly.GetEntryAssembly();
string resName = asm.GetName().Name + ".g.resources";
using (var stream = asm.GetManifestResourceStream(resName))
using (var reader = new System.Resources.ResourceReader(stream))
{
var paths = from entry in reader.Cast<DictionaryEntry>()
where ((string)entry.Key).Contains("sub-folder-name")
select entry.Key;
if (paths.Any())
{
foreach (string path in paths)
{
Uri uri = new Uri(String.Format(
"pack://application:,,,/{0};component{1}", asm.GetName(), path)
, UriKind.Absolute);
//use the uri for the rest
}
}
}
但我仍然需要使用直接(可通過select entry.Value
在上面的LINQ表達式檢索)的資源流,這是UnmanagedMemoryStream
一個實例。我需要MemoryStream
來構建我的對象,但我沒有發現任何優雅的轉換方法。
也許你可以在這個問題的答案中找到一些幫助:http://stackoverflow.com/questions/2517407/enumerating-net-assembly-resources-at-runtime – Teudimundo