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

Base_oM: Adding Enumeration object #1294

Merged
merged 3 commits into from
Nov 16, 2021

Conversation

adecler
Copy link
Member

@adecler adecler commented Oct 1, 2021

Issues addressed by this PR

Closes #1293

See issue. Current implementation in the context of the Embodied Carbon toolkit

Test files

https://burohappold.sharepoint.com/:f:/r/sites/BHoM/02_Current/12_Scripts/02_Pull%20Request/BHoM/BHoM/Base_oM/%231294%20-%20Enumeration?csf=1&web=1&e=eX3XoG
You will need the following PRs to do the testing:

Additional comments

There's a lot that can be done to make the Enumerations more user friendly in the UI (e.g. make it behave exactly like a regular enum in the UI) but this PR is just about laying the foundation for this new type of object. It has been working great for me in the context of the Carbon calculator tool for all stages of workflow so I am pretty confident it is safe to merge. Make sure to play with the test file though.

@adecler adecler added the status:do-not-merge For instance, test PR, for discussion, or dependant PRs not ready for merge label Oct 1, 2021
@adecler adecler self-assigned this Oct 1, 2021
@adecler adecler added the type:feature New capability or enhancement label Oct 1, 2021
@adecler adecler removed the status:do-not-merge For instance, test PR, for discussion, or dependant PRs not ready for merge label Oct 28, 2021
@adecler adecler force-pushed the EmbodiedCarbon_Toolkit-#1-InitialVersion branch from dbdedb5 to 2d394c0 Compare October 28, 2021 08:00
@adecler adecler marked this pull request as ready for review October 28, 2021 08:02
@adecler adecler requested a review from al-fisher as a code owner October 28, 2021 08:02
@adecler adecler requested a review from IsakNaslundBh October 28, 2021 08:02
@adecler adecler force-pushed the EmbodiedCarbon_Toolkit-#1-InitialVersion branch from a1bbf01 to 17155b1 Compare November 12, 2021 03:30
Copy link
Contributor

@IsakNaslundBh IsakNaslundBh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things work as expected with the provided test file.

Have left some comments below with some questions/comments.

Comment on lines +109 to +127
public static bool Equals(IEnum a, IEnum b)
{
if (a == null || b == null)
return false;

return a.GetType().Equals(b.GetType())
&& a.Value.Equals(b.Value);
}

/***************************************************/

public static IEnumerable<T> GetAll<T>() where T : Enumeration
{
return typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
.Select(f => f.GetValue(null))
.Cast<T>();
}

/***************************************************/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, these methods really should live in the Engine. Ok for that to happen in a subsequent PR, but if an issue can be raised to capture that!

Copy link
Member Author

@adecler adecler Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too sure about that.

Enumeration.GetAll<T>() would translate into something like BH.oM.Base.Query.Values<T>() and therefore give a component like

image

One key point of separating the methods into the Engine is to provide a matching functionality in the UI but I'd rather not have that Values component in the UI as it makes absolutely no sense. We have an EnumerationValues method already (it is still in the EmbodiedCarbon toolkit though). So, ultimately, I'd rather delete GetAll<T>() then.

On a similar vein (although I am a bit more hesitant on this one), I prefer static bool Equals(IEnum a, IEnum b) to be in the object definition. The whole purpose of this method compared to the non-static alterative is that it allows to make it more readable in the code that we are comparing Enumerations by having a clear call to Enumeration.Equals and shorter way to handle null values. If we take that away by moving it to an Engine method Query.Equals, we might as well remove that method altogether. Admittedly, there isn't much reason right now to keep it so happy to do just that. It could become handy if we add implicit casting from string (something I would like to add later) though.


namespace BH.oM.Base
{
public interface IEnum : IComparable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question here, not really a change request, but any reason why this is not implementing IComparable<IEnum> instead of for object? Also, with the additional override methods required, could it not also implement IEquatable<IEnum> ? Seems like a close overlap.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have switched to IComparable<IEnum>.
I haven't added IEquatable<IEnum> because it requires an additional Equals(IEnum) and I don't see the point of that. It's not like we are using it anywhere else either.

Copy link
Contributor

@IsakNaslundBh IsakNaslundBh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving after discussion abut the below points.

@adecler
Copy link
Member Author

adecler commented Nov 16, 2021

@BHoMBot check required

@bhombot-ci
Copy link

bhombot-ci bot commented Nov 16, 2021

@adecler to confirm, the following checks are now queued:

  • code-compliance
  • documentation-compliance
  • project-compliance
  • core
  • null-handling
  • serialisation
  • installer
  • versioning

Copy link
Contributor

@FraserGreenroyd FraserGreenroyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have discussed with @adecler to raise an issue for virtual keyword compliance and merge this PR as is with dispensation on that check, with the virtual stuff being fixed in a smaller PR.

@adecler
Copy link
Member Author

adecler commented Nov 16, 2021

@FraserGreenroyd , I have raised teh issue about the missing virtual keyword here: #1324
Will get on it tomorrow

@bhombot-ci
Copy link

bhombot-ci bot commented Nov 16, 2021

FAO: @FraserGreenroyd
@FraserGreenroyd is seeking dispensation on this Pull Request to skip a required check. Please can you provide authorisation for the check to be skipped, or provide assistance as appropriate.

The check they wish to have dispensation on is code-compliance.

If you are providing dispensation on this occasion, please reply with:

@BHoMBot this is a CI/CD instruction. I am authorising dispensation to be granted on check ref. 4222680812

@FraserGreenroyd
Copy link
Contributor

@BHoMBot this is a CI/CD instruction. I am authorising dispensation to be granted on check ref. 4222680812

@bhombot-ci
Copy link

bhombot-ci bot commented Nov 16, 2021

@FraserGreenroyd I have now provided a passing check on reference 4222680812 as requested.

@FraserGreenroyd
Copy link
Contributor

@BHoMBot check copyright-compliance
@BHoMBot check ready-to-merge

@bhombot-ci
Copy link

bhombot-ci bot commented Nov 16, 2021

@FraserGreenroyd to confirm, the following checks are now queued:

  • copyright-compliance
  • ready-to-merge

@bhombot-ci
Copy link

bhombot-ci bot commented Nov 16, 2021

@adecler just to let you know, I have provided a check-installer result to this Pull Request as it was detected to be linked to other Pull Requests in a series. The comment which triggered this check came from @adecler on BHoM_Engine

@bhombot-ci
Copy link

bhombot-ci bot commented Nov 16, 2021

@adecler just to let you know, I have provided a check-versioning result to this Pull Request as it was detected to be linked to other Pull Requests in a series. The comment which triggered this check came from @adecler on BHoM_Engine

@FraserGreenroyd
Copy link
Contributor

@BHoMBot check ready-to-merge

@bhombot-ci
Copy link

bhombot-ci bot commented Nov 16, 2021

@FraserGreenroyd to confirm, the following checks are now queued:

  • ready-to-merge

@FraserGreenroyd FraserGreenroyd merged commit db75d2b into main Nov 16, 2021
@FraserGreenroyd FraserGreenroyd deleted the EmbodiedCarbon_Toolkit-#1-InitialVersion branch November 16, 2021 11:10
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

Successfully merging this pull request may close these issues.

Adding Enumeration object that can implement an interface
3 participants