打包 uri 验证
验证是否可以找到包 uri 的最简单方法是什么?
例如,
pack://application:,,,Rhino.Mocks;3.5.0.1337;0b3305902db7183f;component/SomeImage.png
如何检查图像是否确实存在?
干杯,
贝里尔
What is the simplest way to verify that a pack uri can be found?
For example, given
pack://application:,,,Rhino.Mocks;3.5.0.1337;0b3305902db7183f;component/SomeImage.png
how would I check whether the image actually exists?
Cheers,
Berryl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找不到这个问题的简单答案,因此我最终编写了自己的代码来完成与图像资源相关的三件事:
(1) 具有包 uri 的字符串表示形式(数据绑定)
(2)验证图像是否位于我认为它所在的位置(单元测试)
(3) 验证 pack uri 是否可用于设置图像(单元测试)
这并不简单,部分原因是因为 pack uri 一开始有点令人困惑,并且有多种风格。此代码适用于表示 VS 程序集中包含的图像的包 uri(本地程序集或具有“资源”构建操作的引用程序集)。此 msdn 文章 阐明了这在上下文中的含义。您还需要了解更多有关程序集和构建的信息,这可能比最初看起来更好希望
这对其他人来说更容易,
贝里尔
I couldn't find a simple answer to this, so I wound up rolling my own code to accomplish three things with respect to image resources:
(1) have a string representation of a pack uri (databind)
(2) verify that the image is located where I think it is located (unit test)
(3) verify that the pack uri can be used to set an image (unit test)
Part of the reason this isn't simple is because pack uri's are a bit confusing at first, and come in several flavors. This code is for a pack uri that represents an image that is included in a VS assembly (either locally or a referenced assembly with a build action of 'resource'. This msdn articles clarifies what that means in this context. You also need to understand more about assemblies and builds than might initially seem like a good time.
Hope this makes it easier for someone else. Cheers,
Berryl
我知道,这个问题很老了,但也许有人也有同样的问题。
我还遇到了一个问题,我想在单元测试中测试我的资源字符串。
最简单的解决方案是初始化 ResourceDictionary。您还可以使用dictionary.Keys["myKey"]访问特定键并检查内容。
顺便说一下,这是我在 App.xaml.cs 中注册资源的方式(这样我就可以在每个单元测试中测试它们):
在 OnStartup 中:
I know, the question is very old, but maybe someone has the same problem.
I also had the problem that I wanted to test my resource strings in a unit test.
The simplest solution is to initialize a ResourceDictionary. You can also access a specific key with dictionary.Keys["myKey"] and check the content.
By the way, this is the way I register my resources in the App.xaml.cs (so i can test them per unit test):
And in OnStartup: