GetDisplayName()
Converts the pascal-cased Name property of a type to a displayable name.
Source
public static class CodeExpressionExtensions
{
public static string GetDisplayName(this Type input)
{
string displayName = input.Name;
for (int i = displayName.Length - 1; i >= 0; i--)
{
if (displayName[i] == char.ToUpper(displayName[i]))
if (i > 0)
displayName = displayName.Insert(i, " ");
}
return displayName;
}
}
Example
comboBox1.DisplayMember = "Name";
comboBox1.DataSource = typeof(CodeExpression).Assembly.GetTypes().Where(t => t.BaseType == typeof(CodeExpression)).Select(t => new { Name = t.GetDisplayName(), Type = t }).ToList();