-
Notifications
You must be signed in to change notification settings - Fork 22
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
Object expression #10
Conversation
This will support follow syntax ///provider.fs
type IColor =
abstract member Color : string
type IBarcode =
abstract member Barcode : string
type ISize =
abstract member Size : int
type IItem =
abstract member Id : int
abstract member Name : string
abstract member Art : string
abstract member Number : int
[<CLIMutable>]
type EOrder=
{ Id: int
Items : IItem list
OrderNumRange: string }
///customer.fs
type Item1 =
inherit IItem
inherit IBarcode
type Item2 =
inherit IItem
inherit ISize
inherit IColor
let item1 =
{ new Item1 with
member this.Id = 0
member this.Art = "art"
member this.Name = "name"
member this.Number = 1000
member this.Barcode = "7254301" }
let item2 =
{ new Item2 with
member this.Id = 0
member this.Art = field
member this.Name = "name"
member this.Number = 1000
member this.Color = "red"
member this.Size = 39}
let tp = item1.GetType()
FSharpJsonConverter.registerInheritedConverterType<IItem>(tp)
let eorder = { Id = 1; Items = [item1]; OrderNumRange = "" }
let queryedEOrder =
db
|> LiteRepository.insertItem eorder
|> LiteRepository.query<EOrder>
|> LiteQueryable.first
match queryedEOrder.Items with
| [item] ->
let t = item :? IBarcode
match item with
| :? IBarcode as item1 ->
printfn "%A" item1.Barcode
pass()
| _ -> fail()
| _ -> fail() the |
Hello @humhei this is very interesting and useful! I need to look closely at the code, at first sight there are a couple of things,
Thanks a lot! |
I will do it
Are concurrentDictionary has any disadvantage? |
In practice no, it is ok to keep it 😄 let me know when you finish, and I will merge/publish etc. |
I wil fix it tomorrow. |
Sure buddy, good night! |
@Zaid-Ajaj there are some limitations of fsharp(I think) that restraint this feature |
Yes this is a limitation of F# that is does not have structural equality by default but is this a limitation for this feature?
No need for a fsharp language feature just for this, it doesn't make sense in the first place to do structural equality on arbitrary interfaces
That is not a limitation, the code is correct: the list is generated only once, whether you generate it inside the object expression or outside, it doesn't matter Looking the decompiled C# from compiled IL isn't helpful as this is the result of many compiler optimizations Can you please remove the details on decompiled C# from the readme? if this is an actual problem (I don't think that is the case) then open an issue |
@humhei It is the same code, the list is generated once, no limitation of F# or anything |
@Zaid-Ajaj |
@Zaid-Ajaj Let's merge it? |
Open a issue in fsharp suggestion may be the last strategy i would take |
Yeah it is ok to add the feature here because it does not conflict with the main api, but in the future I would rather not add it unless many users ask for it (the same with |
@Zaid-Ajaj finally find the way worked for me See Tests.typeinherited.fs for detail |
@humhei Nice! Why don't you send a PR then 😉 |
Any ideas about this feature?
See Tests.ObjectExpression for details