You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This arose from a tangential comment in the Peek Definition PR.
Currently, we make use of enum to describe how to layout our menus. This is less than optimal for at least 3 reasons:
We're basically duplicating the names; as a member of an enum and as a menu command. This kind of violates the DRY principles and also thwarts any compile-time checks for the consistency of the menu structure.
The menu layout is technically more data than code.
We are mixing concerns --- we describe the layout in an enum but then we describe the BeginGroup as an override in the corresponding command.
This was developed with a earlier version of C#, and we need to work with commandbar system (blargh) so we can't use XAML or something similar.
However, with C# now featuring nameof() operator, we could consider converting the enum into a static class. Something like this:
public static class MenuLayout
{
private static readonly List<string> _list => new List<string>
{
nameof(OneCommand),
nameof(AnotherCommand),
default, //indicates a begin group?
nameof(MoreCommand)
}
public static string GetElement(int index) => _list.Index(index);
}
The advantage gained is that the nameof operator affords us the type safety and compile-time validation and ability to refactor the command's name without breaking the menu layout.
Note: I suppose it could be a List<Command> instead of List<string> but I'm not 100% sure if there's a need to make it stringified or something. I also am not 100% sold on inserting default as a stand-in for inserting a separator (e.g. BeginGroup).
Would that help improvement our management of the menu layout?
This arose from a tangential comment in the Peek Definition PR.
Currently, we make use of enum to describe how to layout our menus. This is less than optimal for at least 3 reasons:
We're basically duplicating the names; as a member of an enum and as a menu command. This kind of violates the DRY principles and also thwarts any compile-time checks for the consistency of the menu structure.
The menu layout is technically more data than code.
We are mixing concerns --- we describe the layout in an
enum
but then we describe theBeginGroup
as an override in the corresponding command.This was developed with a earlier version of C#, and we need to work with commandbar system (blargh) so we can't use XAML or something similar.
However, with C# now featuring
nameof()
operator, we could consider converting the enum into a static class. Something like this:The advantage gained is that the
nameof operator
affords us the type safety and compile-time validation and ability to refactor the command's name without breaking the menu layout.Note: I suppose it could be a
List<Command>
instead ofList<string>
but I'm not 100% sure if there's a need to make it stringified or something. I also am not 100% sold on insertingdefault
as a stand-in for inserting a separator (e.g.BeginGroup
).Would that help improvement our management of the menu layout?
Originally posted by @bclothier in #5751 (comment)
The text was updated successfully, but these errors were encountered: