NETCoreBlockly icon indicating copy to clipboard operation
NETCoreBlockly copied to clipboard

Ordinals use the order in the list, not any assigned value.

Open djaus2 opened this issue 1 year ago • 5 comments

Following on from issue: #174 Given an enum type as parameter to a Controller can the enum literals show rather than the ordinal? which is closed.,

When the ordinals are used to set a value and a specific enum value is chosen then you get its order from zero in the list, not any assigned value. For eaxample:

        public enum GroveGPIOPin { p16, p17, p18, p19, p20, p21 }
        public enum GroveGPIOPinX { pp16=16, pp17=17, pp18=18, pp19=19, pp20=20, pp21=21 }

When either is used as a parameter for a controller, you get values 0 ...5 for both. Not 16 to 21 for the second enum type.

Whilst this is not a breaking issue, it might be confusing for those not knowing this. Knowing it, is easy to work around, provided all values as sequential by one. You just add the expected first value to the value given for the selected enum. That is for GroveGPIOPinX just add 16 within teh controller.

djaus2 avatar Sep 20 '24 06:09 djaus2

I understand the problem. I think that I assume in the code the values. I will try to see how it is generated and modify the code accordingly

ignatandrei avatar Sep 22 '24 09:09 ignatandrei

Further more, its taking that order number and trying to cast it to one of the enum ordinals and generally failing. For example using GroveGPIOPinX as a controller method parameter , if pp16 is used as the input to a block, it is been passed as 0 being first in the list then the controller tries to cast it thus (GroveGPIOPinX )0 which fails as 0 is not an ordinal in GroveGPIOPinX .

djaus2 avatar Sep 23 '24 02:09 djaus2

I have blogged extensively about all of this here https://davidjones.sportronics.com.au/tags/enums/

djaus2 avatar Sep 24 '24 11:09 djaus2

I did not forget. Just do not have time yet. Maybe next week

ignatandrei avatar Oct 20 '24 17:10 ignatandrei

Ok thx

David Jones (MVP)


From: Andrei Ignat @.> Sent: Monday, October 21, 2024 4:36:07 AM To: ignatandrei/NETCoreBlockly @.> Cc: David Jones (MVP) @.>; Author @.> Subject: Re: [ignatandrei/NETCoreBlockly] Ordinals use the order in the list, not any assigned value. (Issue #174)

I did not forget. Just do not have time yet. Maybe next week

— Reply to this email directly, view it on GitHubhttps://github.com/ignatandrei/NETCoreBlockly/issues/174#issuecomment-2425145249, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AC7U2EP4OJFF4Z7BCG6AZWTZ4PSYPAVCNFSM6AAAAABORK34A2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRVGE2DKMRUHE. You are receiving this because you authored the thread.Message ID: @.***>

djaus2 avatar Oct 20 '24 21:10 djaus2