There are some cases where enum values we would like to convert to smart enums are used as flags. It would be great to redo these bindings as smart enums.
For example:
In https://github.com/xamarin/xamarin-macios/pull/7316
We add new enum values to AVFoundation.cs and AVFoundation\Enums.cs. This seems like a great use case for smart enums but we can't use a smart enum because it's used as a flag in AVMetadataObject.cs:
internal static AVMetadataObjectType ArrayToEnum (NSString[] arr)
{
AVMetadataObjectType rv = AVMetadataObjectType.None;
if (arr == null || arr.Length == 0)
return rv;
foreach (var str in arr) {
rv |= ObjectToEnum (str);
}
return rv;
}
So what was done before, e.g. in src/Vision/VNBarcodeSymbologyExtensions.cs, is not identical to this case - it was multiple values, but without being a [Flag]
Since the to/from-flag logic resides in 2 methods, separate from the NSString/enum conversions, I think this (and similar cases) can be moved to smart enums.
IOW we just need to change the to/from-flag methods to use the smart enum helpers - and since that's independent of the items then we have the benefits (no manual updates required)
We can also generalize the * to/from-flag* code to avoid using the enum type - so it can be reused elsewhere (if needed). Still that does not require generator changes IMO.
yes, it's orthogonal (does not stop using smart enums)
PR coming (works but missing tests), but not a generator enhancement - closing
Most helpful comment
yes, it's orthogonal (does not stop using smart enums)
PR coming (works but missing tests), but not a generator enhancement - closing