Tom*_*Tom 0 c# string intellisense dictionary visual-studio
有没有办法获得Dictionary<string,string>
C#中所有键的intellisense ?
或者是否可以获得具有字符串参数的方法的intellisense.
我希望有类似的东西ResourceManager.GetString("")
.如果可能的话,我不想创建一个带有常量字符串的静态类来模拟它.
编辑:
我目前正在使用字典将多个资源文件合并到一个字典中,这样做是因为资源在多个项目中使用并且需要覆盖.
var temp = ResourceFile1.ResourceManager
.GetResourceSet(CultureInfo.CurrentUICulture, true, true)
.Cast<object>()
.Select(
x => new
{
ID = 1,
Value = x.GetType().GetProperty("Value").GetValue(x, null).ToString(),
Key = x.GetType().GetProperty("Key").GetValue(x, null).ToString()
});
temp = temp.Concat(
ResourceFile2.ResourceManager
.GetResourceSet(CultureInfo.CurrentUICulture, true, true)
.Cast<object>()
.Select(
x => new
{
ID = 2,
Value = x.GetType().GetProperty("Value").GetValue(x, null).ToString(),
Key = x.GetType().GetProperty("Key").GetValue(x, null).ToString()
}));
temp = temp.Concat(
ResourceFile3.ResourceManager
.GetResourceSet(CultureInfo.CurrentUICulture, true, true)
.Cast<object>()
.Select(
x => new
{
ID = 3,
Value = x.GetType().GetProperty("Value").GetValue(x, null).ToString(),
Key = x.GetType().GetProperty("Key").GetValue(x, null).ToString()
}));
ResourceDictionary = temp.GroupBy(x => x.Key)
.Select(x => x.FirstOrDefault(c => c.ID == x.Max(v => v.ID)))
.ToDictionary(x => x.Key, x => x.Value);
Run Code Online (Sandbox Code Playgroud)
如果您知道有限值,请不要使用字符串,但在这种情况下使用枚举.
根据定义,string可以在运行时包含任何值,而枚举在编译时是已知的.
或者你可以简单地避免使用字典.如果您知道您的词典将始终包含相同的键,则最好创建一个类,其中每个键以前使用过一个属性.