speckleworks / SpeckleCore

Check a brand new Speckle at: https://github.com/specklesystems
https://speckle.systems
MIT License
38 stars 17 forks source link

Revamp converter flow #45

Closed didimitrie closed 6 years ago

didimitrie commented 6 years ago

Speckle Core converter should be the single point of contact for conversions, and the application specific converters should just add extension methods to their types, for which the core converter will look into.

Flow as it is now:

Object -> AppConverter (ie, rhinoconverter) -> checks type & converts | tries to convert to abstract -> converted object

Flow as it can be:

Object -> SpeckleCore.Converter.Convert -> checks for extension method "ToSpeckle" -> if yes, returns the result of that, if not converts to abstract

Simpler clearer and less switches! Or just switching problems around? 🤔

didimitrie commented 6 years ago

This is now fixed. Not sure if it's an enhancement or a downgrade in performance, so there's still testing to do. Nevertheless, the lazy developer can just do

SpeckleObject myObj = SpeckleCore.Converter.Serialise( anyObject ) ;

And she/he will get a null in case of nuclear disaster, or a SpeckleAbstract if no conversion method is defined in any loaded assembly, or a converted speckle object if a ToSpeckle extension method is found in any of the loaded assemblies that contain "Speckle" and "Converter" in their names.

Problem: it seems to be slower than expected, but then again - this all happens in the background, so...

didimitrie commented 6 years ago

I'll close for now, as it seems like main performance bottleneck was in the rhino selection events :/ (https://github.com/speckleworks/SpeckleRhino/issues/106)