I am a new developer and this is the first time that I have worked with a winform and in addition I am taking over someone else's project, so there are things that I do not fully understand.
I have an "Item to modify" dropdown displayed and this list was made this way: "public DisplayItem HorseName {get; set;}", so the terms in my dropdown are displayed like this and I would like to divide them into 2 when there is an uppercase example: Horse Name. I don't know if I should do a Split or a Regex.Replace and especially where to do it since it's a list of "item to modify" which goes through 2-3 places. My guest would be after the k.Name in the request, but it didn't work.
As I tell you the starting code is not mine, so the place where to place it leaves me perplexed
This is my code:
[NonSerialized]
public static Dictionary<string, PropertyInfo> DisplayItemProperties;
static DisplaySettings()
{
DisplayItemProperties = (from p in typeof(DisplaySettings).GetProperties()
where p.PropertyType == typeof(DisplayItem)
select p).ToDictionary(k => k.Name, v => v);
}
public IEnumerable<DisplayItem> DisplayItems()
{
return DisplayItemProperties.Select(item => item.Value.GetValue(this, null)).Cast<DisplayItem>();
}
this.cbDisplaySetting.Items.AddRange(DisplaySettings.DisplayItemProperties.Keys.Cast().ToArray());
SOLUTION:
This:
this.cbDisplaySetting.Items.AddRange(DisplaySettings.DisplayItemProperties.Keys.Cast<object>().ToArray());
became:
List<string> itemsLst = DisplaySettings.DisplayItemProperties.Keys.ToList<string>();
for(var i = 0; i < itemsLst.Count; i++)
{
itemsLst[i] = Regex.Replace(itemsLst[i], "(\\B[A-Z])", " $1");
}
this.cbDisplaySetting.Items.AddRange(itemsLst.Cast<object>().ToArray());