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

Support F# Discriminated Unions #66

Closed
xperiandri opened this issue Apr 27, 2020 · 9 comments
Closed

Support F# Discriminated Unions #66

xperiandri opened this issue Apr 27, 2020 · 9 comments

Comments

@xperiandri
Copy link

Is your feature request related to a problem? Please describe.
I cannot use F# discriminated unions, in particular, single case unions as properties.

Describe the solution you'd like
Implement Gremlinq converted based on Newtonsoft's DiscriminatedUnionConverter

Additional context

[<Struct>]
type DomainID<'t> = private DomainID of Guid

type UzantoID = DomainID<Uzanto>
and Uzanto =
    { [<JsonProperty("id")>]
      ID : UzantoID
      PhoneHash : SingleLineText<PhoneHash>
...
@xperiandri
Copy link
Author

Maybe I don't understand the serialization mechanism or I cannot find a way to transform property value to Gremlinq supported type before serialization?

@danielcweber
Copy link
Contributor

Not sure what you are proposing I'm afraid

@xperiandri
Copy link
Author

Let's have a look at DomainID type which is a wrapper around Guid

[Serializable, StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Size=1), Struct, 
public struct DomainID<t> : IEquatable<DomainID<t>>, IStructuralEquatable, IComparable<DomainID<t>>, IComparable, IStructuralComparable 
{
     internal Guid item;
     [CompilationMapping(SourceConstructFlags.UnionCase, 0)]
     internal static DomainID<t> NewDomainID(Guid item) =>
          new DomainID<t>(item);

     [CompilerGenerated, DebuggerNonUserCode]
     internal DomainID(Guid item)
     {
         this.item = item;
     }

     [CompilationMapping(SourceConstructFlags.Field, 0, 0), CompilerGenerated, DebuggerNonUserCode]
     internal Guid Item => this.item;
...

As you can see it is a wrapper struct that holds a single value and has phantom generic parameter to distinguish Id for different entities.
When saving it to Gremlin I need a mechanism to unwrap held value and when reading from Gremlin to wrap back.

@xperiandri
Copy link
Author

How can Gremlinq be extended to support such a scenario?

@stale
Copy link

stale bot commented May 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 6, 2020
@danielcweber
Copy link
Contributor

You can see something similar here for TimeSpans-to-double and vice versa conversion. None of this has been released yet though.

@stale stale bot removed the stale label May 7, 2020
@danielcweber
Copy link
Contributor

danielcweber commented May 20, 2020

This scenario is possible with the latest preview, see comment above.

@xperiandri
Copy link
Author

xperiandri commented May 20, 2020

Looks good, thanks!

@xperiandri
Copy link
Author

@danielcweber could you point to the place where I can look at the sample now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants