frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
537 stars 132 forks source link

Is there a way to access the C# Type instead of the Typewriter Type, or its assembly data? #318

Open Prinsn opened 4 years ago

Prinsn commented 4 years ago

My project is currently using Typewriter to generate Typescript models for Breeze and EFCore.

I'm currently trying to convert from a during runtime capture of the set of initialization responses that our framework and Breeze require (eg, the Breeze metadata for schema) to something more elegant, such as the way Typewriter does things.

However, at current, I'm having difficulty figuring out if there's any way to get the required data by reflection to do an Activator.CreateInstancefrom(assembly.CodeBase, type.FullName) or Activator.CreateInstance(type)

I actually didn't know that Typewriter was using its own definition of Type until trying this and getting the mismatch error.

The template I'm trying to implement is roughly

$Class(BlackMagicStringGenerator)[$getResponseStrings[
  export const $getVarName = JSON.stringify($getJsonBody);
]]

Where the composite tuple that is the name and json body are generated and not const.

I should probably be able to hardcode the assembly data, but I was looking for something that wouldn't require magic strings that are hidden from refactoring tools.