Rosetta icon indicating copy to clipboard operation
Rosetta copied to clipboard

Support generic types

Open michaelaird opened this issue 7 years ago • 6 comments

Rosetta should support generic types. Generic types can be used for fields, properties, variables, class types and base class types.

michaelaird avatar Feb 26 '17 12:02 michaelaird

I spent a while poking at implementing this and going in circles.

Here are some issues/thoughts:

  • GenericNameSyntax inherits from SimpleNameSyntax so it should be straightforward to differentiate between them and handle them separately
  • The list of type arguments are also TypeSyntax nodes so they need to be walked recursively
  • TypeReference is a likely candidate for handling generics
    • There are 2 TypeReference helpers, one specifically for BaseTypes of classes. They both need to handle generics properly
  • Currently, type name mapping from C# to TypeScript is taking place outside of TypeReference ( in TypeMappings.MapType which only accepts a string)
    • Many type checks are being done using String.Contains. This could lead odd errors. (eg. a user defined type named UnavoidableIncident would be treated as void )

@andry-tino I'm not sure where to go with this right now so let me know what you think.

michaelaird avatar Feb 26 '17 12:02 michaelaird

Hello and sorry for the long wait. I am pretty busy at the moment, I will get back to you soon! Let me also go through your code and points...

andry-tino avatar Mar 15 '17 16:03 andry-tino

No worries. We're continuing to crank through implementing some more things. On our radar:

  • Switch statements
  • Try/catch blocks
  • CastExpression
  • ArrayCreationExpression
  • ElementAccessExpression
  • LogicalAndExpression
  • LessThanExpression
  • GreaterThanExpression
  • ConditionalExpression
  • LogicalOrExpression
  • AsExpression

michaelaird avatar Mar 15 '17 20:03 michaelaird

Very cool. I have some work I need to prioritize at the moment on the ScriptSharp definition generator. Once done, I will start integrating those changes.

andry-tino avatar Mar 23 '17 11:03 andry-tino

Here's my initial crack at handling generic types(and nullable types, and arrays and some other bits).

https://github.com/michaelaird/Rosetta/commit/e7e92dca146660de1123c391bfcb46f10f2a0eb3

Over the weekend, I'm going to try to also put in calling generic methods.

michaelaird avatar Apr 21 '17 21:04 michaelaird

Yes seems a good start. I am finalizing my changes for supporting ScriptSharp TS definition file generation via assembly only. After that I will have more times for integrating your changes.

andry-tino avatar Apr 22 '17 04:04 andry-tino