Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

enum managed / native size #150

Open
spouliot opened this issue Apr 12, 2018 · 2 comments
Open

enum managed / native size #150

spouliot opened this issue Apr 12, 2018 · 2 comments
Assignees
Milestone

Comments

@spouliot
Copy link

The managed enum size should, when possible, match the native one. E.g.

using System;
using System.Runtime.InteropServices;
using SwiftRuntimeLibrary;
using SwiftRuntimeLibrary.SwiftMarshal;
namespace XamVersions
{
    [SwiftEnumHasRawValue(typeof(long))]
    [SwiftEnumType("libXamVersions.dylib", "_T011XamVersions8SemanticOMn", 
        "_T011XamVersions8SemanticON", "")]
    public enum Semantic
    {
        Major, 
        Minor, 
        Patch, 
        Same, 
            
            Unknown
        }
}

should be public enum Semantic : long as this will help if that same type is used in C or ObjC intro with other API. If the size don't match then extra, manual code is required (and that often leads to mistakes).

The [Native] attribute (from XI/XM) can also be used when a enum is based on n[u]int (NS[U]Integer) as we have some tooling to spot those cases.

@spouliot spouliot self-assigned this Apr 25, 2018
@spouliot
Copy link
Author

The test (minimally) and the runner (ideally, sooner than later) needs to add a reference to Xamarin.[iOS|Mac|TVOS|WatchOS].dll assemblies.

This time it's for [Native] attribute (on Int based swift enums) but it will be required for memory management and NSObject compatibility.

@spouliot
Copy link
Author

[SwiftEnumBackingType] serve the same purpose than [Native]. The main difference is that the type is always encoded (not inferred).

In theory we don't need both, in practice there's code that use [Native] that might need to be shared.

There's also the case where type X exists for ObjC (and inside the platform assembly) where we do not want to duplicate the definition.

E.g. a NSFooEnum could be used in C API (p/invoke), ObjC API and Swift API.

We already share the same definition for C/ObjC. To share with Swift we'll need to see when other attributes, e.g. SwiftEnumType, are really required.

@stephen-hawley stephen-hawley transferred this issue from another repository Oct 29, 2019
@chamons chamons added this to the Future milestone Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants