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
Currently enum values are shown as they are defined in the code. For example, Central Europe will show as CentralEurope since we cannot have spaces in an enum name.
To solve that, I have been using the Description attribute to store a UI friendly text representation along with my own methods to convert enums to and from text. As the number of cases for this solution grows, it would be better to switch to a centralised solution.
It is however important to not that, within the BHoM, the Description attribute has already been used on enums to provide actual descriptions and cannot therefore be used to contain the display text.
I suggest to use a new attribute: DisplayTextAttribute that will serve that single purpose. The ParseEnum method in the engine will need to be updated to support that new attribute. We will also need to update teh ToText method so it now looks for the DisplayText attribute on enum values.
The text was updated successfully, but these errors were encountered:
Hi @adecler just wondering if there's any benefit to just adding the ability to split an enum value at a capital letter and space it out to avoid another attribute to look after?
var enumOptions = Enum.GetValues(typeof(NonProjectOption));
var r = new Regex(@"
(?<=[A-Z])(?=[A-Z][a-z]) |
(?<=[^A-Z])(?=[A-Z]) |
(?<=[A-Za-z])(?=[^A-Za-z])", RegexOptions.IgnorePatternWhitespace);
List<string> options = new List<string>();
foreach (var option in enumOptions)
options.Add(r.Replace(option.ToString(), " "));
This is something I did for a similar use case - however, I do accept this only allows us to change CentralEurope to Central Europe whereas I'm guessing your approach would allow us to change it to be Central EU - covering the mainland countries (i.e. being able to add more text 'description' to the value)?
@FraserGreenroyd , that is not always that simple.
I have other cases where the enum needs to look something like this: 1. Substructure for example.
Any special character is causing problems so it is simpler to let the coder define exactly how the enum needs to look instead of trying to come up with conventions for each special case.
Description:
Currently enum values are shown as they are defined in the code. For example, Central Europe will show as
CentralEurope
since we cannot have spaces in an enum name.To solve that, I have been using the
Description
attribute to store a UI friendly text representation along with my own methods to convert enums to and from text. As the number of cases for this solution grows, it would be better to switch to a centralised solution.It is however important to not that, within the BHoM, the
Description
attribute has already been used on enums to provide actual descriptions and cannot therefore be used to contain the display text.I suggest to use a new attribute:
DisplayTextAttribute
that will serve that single purpose. TheParseEnum
method in the engine will need to be updated to support that new attribute. We will also need to update teh ToText method so it now looks for theDisplayText
attribute on enum values.The text was updated successfully, but these errors were encountered: