Bra*_*don 9 c# reflection embedded-resource
标题总结得很好.我知道我可以使用以下方法获取嵌入式资源名称:
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
string[] files = assembly.GetManifestResourceNames();
Run Code Online (Sandbox Code Playgroud)
但我希望能够从特定文件夹中获取嵌入式资源.或者至少能够区分来自不同文件夹的嵌入资源.
Tim*_*ver 11
资源以以下格式返回.
[Namespace].[Folder].[Filename]
Run Code Online (Sandbox Code Playgroud)
请注意,路径中的所有文件夹都以.'s 分隔.因此,如果您有一个具有以下配置的嵌入式资源
myproject.csproj (Namespace = com.mycompany.myproject)
- Resources
- Images
- Icons
- my_icon.ico
资源名称将是......
com.mycompany.myproject.Resources.Images.Icons.my_icon.ico
Run Code Online (Sandbox Code Playgroud)
如果要从特定文件夹中选择所有文件夹,可以使用以下LINQ表达式或根据需要进行修改.
string prefix = "your_namespace.your_folder."
var resourceNames = Assembly.GetExecutingAssembly()
.GetManifestResourceNames()
.Where(name => name.StartsWith(prefix));
Run Code Online (Sandbox Code Playgroud)