我如何从资源对象的资源名称? [英] How do I get the resource name from the resource object?

查看:176
本文介绍了我如何从资源对象的资源名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有加入到我的资源文件夹中的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是百合

这篇关于我如何从资源对象的资源名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆