c# - 从程序集中获取所有资源的列表

标签 c# wpf

我有一个包含Resources 的文件夹,我想获得一个包含所有路径 的列表。

enter image description here

如果我将它们设置为嵌入式资源,我可以通过以下方式获取它们

var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();

当遵循这个答案时 https://stackoverflow.com/a/1935035/6229375 , 我不应该再使用 embedded resource 或者我做错了什么?

最佳答案

来自以下blog post :

Files marked with build action of “Resource” are added to a special resx file called ProjectName.g.resx. This file is generated during the build, it is not part of the project. You can access content of the ‘Resource’ files by creating an instance of ResourceManager and calling GetStream(filename). Additionally, in WPF applications you can access these resources via Application.GetResourceStream() in C# and via things like in XAML.

   var resourceManager = new ResourceManager("ConsoleApp5.g", Assembly.GetExecutingAssembly());
    var resources = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true,
true);
    foreach (var res in resources)
    {
        System.Console.WriteLine(((DictionaryEntry)res).Key);
    }

其中 ((DictionaryEntry)res).Value 将是 Stream。

关于c# - 从程序集中获取所有资源的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52179108/

相关文章:

c# - WPF 中的单元测试 View

c# - 限制访问,直到用户确认电子邮件链接

c# - 如何获取通过 ADB 使用的当前键盘(当前 IME)

c# - 如何按表列过滤 LINQ 查询并获取计数

C# 初学者学习 : To do a project without having read big concepts

wpf - Binding UpdateSourceTrigger=Explicit,在程序启动时更新源

c# - Paypal IPN 返回无效,不知道为什么

c# - 使用 linq 的 WPF 组合框绑定(bind)

c# - WPF 复合控件

c# - 如何在 ViewModel 类中执行 ComboboxSelectionChanged 方法