列出c#lib中标记为Resource的所有文件

Vla*_*lad 1 c#

是否可以列出所有已添加到程序集中并标记为资源(未嵌入)的文件。

我已经尝试过GetManifestResourceNames方法。它仅适用于嵌入式资源。但是我需要将这些文件标记为资源,以便通过使用uri这样的来访问该文件:pack:// application:,, / ApplicationName; component / Resources / logo.png

谢谢

Ale*_*ici 5

您可以像这样访问它:

var image = new BitmapImage(new Uri("pack://application:,,,/ApplicationName;component/Resources/logo.png", UriKind.Absolute))
Run Code Online (Sandbox Code Playgroud)

[编辑]

您可以通过调用此方法列出所有它们:

public static string[] GetResourceNames()
{
    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))
    {
        return reader.Cast<DictionaryEntry>().Select(entry => (string)entry.Key).ToArray();
    }
}
Run Code Online (Sandbox Code Playgroud)