ignatandrei / NETCoreBlockly

.NET Core API to Blockly - generate from WebAPI, Swagger, OData, GraphQL => https://visualapi.azurewebsites.net/
https://ignatandrei.github.io/BlocklyAutomation/
MIT License
175 stars 37 forks source link

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

Open djaus2 opened 2 weeks ago

djaus2 commented 2 weeks ago

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.

ignatandrei commented 2 weeks ago

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

djaus2 commented 1 week ago

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 commented 1 week ago

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