Closed realvictorprm closed 6 years ago
Side note, it was really fun to write this! :smile:
I'm not familiar with F#. Are you saying we should consider using F# instead of C# to generate the C# code?
I think F# could reduce the amount of needed code and aditionally adds safety.
It would be awesome if you would switch to F# in this repository. F# would definitely fit better here.
Currently I'm trying to rewrite the complete code of this repository in F#, I hope to be able to present it to you soon.
PS: Don't worry, C# compatibility persist with F#
I'm still on it. Just a bit occupied with the F# compiler too.
I'm delaying this, got too much to do. Sorry :-(
I've played around with F# and the json files of glTF. Result is that I can generate easily a single support file which reduces manual work of schema mapping without loosing control.
For the source code see my gist here.
With F# it's a lot easier to parse glTF without loosing much flexibility. To achieve this it's needed to use a JsonTypeProvider plus a auto generated support file which provides both an abstract visitor class and schema classes depending on the specification.
The dependencies of the generated file just consist of
FSharp.Data
and the standard library. An example output of the generator would be:now it would be just needed to inherit from the abstract class to get such sourcefile (currently unfilled).
To start the generation people just need to call the
VisitSchemaDir
method with the path to the schema directory as parameter.This was a proof of concept and also a showcase of how easily such stuff can be written in F# without even touching a single json file manually. My question is, what do you think? Would you like to see more implementation examples? (just note down here, although it's written in F# the visitor class can also be used for generating C# code).