![](/img/trans.png)
[英]How to use strings from Resources.resx file in dynamic data TableName attribute
[英]How to prevent long strings from being written to resx file
即使我的表单未设置为本地化,如果我有一个文本长度超过200个字符的标签,Visual Designer也会将文本放入.resx中,而不是直接在代码中。
这是有问题的,因为我使用的是自定义本地化方法,该方法从代码中提取可本地化的字符串,但它不搜索resx文件。
有没有办法防止这种行为? 我可以在代码中对字符串进行硬编码,以便提取程序可以获取它,但这很烦人,因为在Designer中文本看起来不正确。 另外,我可以使用多个标签,但是感觉很不对。
我见过其他人在其他论坛上也提出类似的问题,但没有答案。
我没有完整的解决方案,但是可以扫描与类型相关联的资源,并找到设计人员决定执行此操作的字符串。
var resources = new ResourceManager(type);
using (var set = resources.GetResourceSet(CultureInfo.InvariantCulture, true, false))
{
if (set != null)
{
foreach (DictionaryEntry res in set)
{
var key = res.Key as string;
var val = res.Value as string;
if (key == null || val == null)
continue;
if (!key.EndsWith(".Text"))
continue;
key = key.Substring(0, key.Length - ".Text".Length);
// key is now the name of your control
// val is the string the designer stored as its Text in the default resource
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.