Is there a way to get intellisense for all the keys in a Dictionary<string,string> in C#?
Or is it possible to get intellisense for a method with a string parameter.
I want to have something like ResourceManager.GetString("") has. and if possible i don’t want to create a static class with constant strings to simulate it.
Edit:
I am currently using a dictionary to combine multiple resource files in to one dictionary, this is done becouse resources are used in multiple projects and need to be overwriten.
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);
Don’t use string, but an enum in this case, if you know the finite values.
By definition, string can contains any value at run-time, while enums are known at compile time.
Or you can simply avoid the use of a dictionary. If you know that your dictionary will contains always the same keys, you should better create a class with one property per key you previously used.