我需要編寫一個程序,該程序從dll讀取所有字符串資源並將它們插入某個表中。我有方法,讀取資源:從資源管理器獲取所有字符串
private static IEnumerable<KeyValuePair<string,string>> getAllResources(ResourceManager resourceManager,
Language language)
{
ResourceSet resourceSet = resourceManager.GetResourceSet(getCulture(language), true, true);
IDictionaryEnumerator dictNumerator = resourceSet.GetEnumerator();
// Get all string resources
while (dictNumerator.MoveNext())
{
// Only string resources
if (dictNumerator.Value is string)
{
var key = (string)dictNumerator.Key;
var value = (string)dictNumerator.Value;
yield return new KeyValuePair<string, string>(key, value);
}
}
}
但是當我開始使用它,我注意到,它也讀出資源,像文件添加(讀取文件內容)
我怎能無視作爲「文件」添加的資源,以及只讀字符串?
難道不可能在值上使用'as'鑄造嗎? –
我可以使用「as」而不是「is」,但它不能解決我的問題 – Oleksey