说我有加入到我的资源文件夹中的EXE文件。现在,我怎么能得到的名称(或者甚至是完整路径从它的链接,这样我还能有文件名)的资源作为字符串?
Say I have an exe added into my resources folder. Now how can I get the name (or even the fullpath from which its linked so that I can still have the file name) of the resource as string?
从 Properties.Resources.myApp 我如何获得字符串对myApp。 toString()方法不起作用。如果重要的是要嵌入文件拿到的名字,我可以
From Properties.Resources.myApp how do I get the string "myApp". ToString() doesnt work. If it is important to embed the file to get the name, I can.
修改我的问题是,没有具体得到名exe文件的资源。但是,一个通用的做法,让我有资源的名称!举例来说,如果我的资源是一个位图图像?我需要从 Properties.Resources.Lily 打印百合。如何实现这一目标? 。的ToString不会不管怎么说工作
My question is not specifically to get the name of exe resource. But that one generic approach which gives me the name of the resource! For instance what if my resource is a bitmap image? I need to print "Lily" from Properties.Resources.Lily. How to achieve this? ToString wont work anyways.
推荐答案这是使用LINQ表达式很简单:
It's quite easy using Linq Expressions:
using System.Linq.Expressions; //... static string GetNameOf<T>(Expression<Func<T>> property) { return (property.Body as MemberExpression).Member.Name; } // Usage: var s = GetNameOf(() => Properties.Resources.Lily);
取值 768,16是百合
更多推荐
我如何从资源对象的资源名称?
发布评论