Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflection_Engine: Expose quantity attributes on enum values #3421

Open
IsakNaslundBh opened this issue Oct 16, 2024 · 0 comments
Open

Reflection_Engine: Expose quantity attributes on enum values #3421

IsakNaslundBh opened this issue Oct 16, 2024 · 0 comments
Assignees
Labels
type:feature New capability or enhancement

Comments

@IsakNaslundBh
Copy link
Contributor

Description:

Related to BHoM/BHoM#1642

Add a couple of lines to this method:

private static string EnumItemDescription(this Type type)
{
FieldInfo[] fields = type.GetFields();
string desc = Environment.NewLine + "Enum values:";
int m = Math.Min(fields.Length, 20);
for (int i = 0; i < m; i++)
{
FieldInfo field = fields[i];
//Skip the value option
if (field.Name == "value__")
continue;
desc += Environment.NewLine;
desc += "-" + field.Name;
DescriptionAttribute attribute = field.GetCustomAttribute<DescriptionAttribute>();
if (attribute != null)
desc += ": " + attribute.Description;
}
if (fields.Length > m)
desc += Environment.NewLine + "-...And more";
return desc;
}

Namely, add in the step

                QuantityAttribute quantity = field.GetCustomAttribute<QuantityAttribute>();
                if (quantity != null)
                    desc += $" [{quantity.SIUnit}]";

After the description attribute to allow for display of quantities relating to enum values.

@IsakNaslundBh IsakNaslundBh added the type:feature New capability or enhancement label Oct 16, 2024
@IsakNaslundBh IsakNaslundBh self-assigned this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New capability or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant