-
Notifications
You must be signed in to change notification settings - Fork 301
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
Reflection for classes #2027
Comments
@alfonsogarciacaro think you could give me guidance on where to start with implementing this? I'd be willing to try a PR if I had a better idea of where to start. |
Well, actually I think @krauthaufen has already done that in #1839 which, besides adding support for quotations, increases the support for reflection. I've been very busy for the last months so I couldn't check the PR properly but time allowing I'll try to start publishing alpha/beta versions of Fable 3 based on the PR soon. In any case, there are instructions in the PR description about how to test it right now. The |
Having trouble with merging master into type A(i1: int, i2: int) =
member x.Value2 = i2 + i2
let inline activate<'T> (args: obj[]) =
System.Activator.CreateInstance(typeof<'T>, args) :?> 'T
let test() =
let a = activate<A> [|4; 5|]
a.Value2 |> printfn "%i"
test() |
You can check the Reflection tests to see what's currently supported. |
I've explored quite a bit with what we can currently reflect when making fast-check bindings for fable.
Yeah, that's what got me thinking about this issue again actually! The issue I'm having that prevents just using that is I need to be able to tell given a |
A class in what sense? Something that's not a record, a union, a tuple, an array or an enum? In that case, maybe you can just write a helper to discard the rest of the options. |
So my use-case is I want to be able to automatically generate an arbitrary of any type using default primitive arbitraries (if necessary). So for example if they have something like this: type MyClass (someNum: int) =
let mutable someInnerState = someNum
member _.AddOne () = someInnerState <- someInnerState + 1 Which I would receive a |
Hmm, this can be done with Activator, but the problem is we cannot know the types of the constructor arguments for a class right now (this can be done with records and unions though), but it would be very interesting for your use case, I'll see what I can do. I was a bit reluctant to include information for all the class members because it could increase the bundle size, but maybe we could generate an independent let inline getMembersOf<'T>() =
typeof<'T>.GetMembers()
getMembersOf<MyClass>() |
Yeah all the types would be known at compile time, that would be great! |
Related #2085 |
I've been working on bindings for fast-check which are mostly complete.
The library has the ability to do model-based testing, which I have implemented:
The thing I'd like to do is automatically generate a complete
Arbitrary<'Msg>
if it's possible as I believe it would make writing these cases even easier.I have reflection working for almost all types, but the thing giving me trouble is getting class constructors.
Is this something that can currently be resolved with Fable? If not, is adding the support for these feasible?
The text was updated successfully, but these errors were encountered: