我如何从资源对象的资源名称?

编程入门 行业动态 更新时间:2024-10-27 04:25:13
本文介绍了我如何从资源对象的资源名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

我如何从资源对象的资源名称?

本文发布于:2023-11-10 03:17:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574207.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资源   对象   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!