Code Monkey home page Code Monkey logo

Comments (4)

gregveres avatar gregveres commented on September 22, 2024 1

I put some examples in this issue: #34

I do exactly this in the examples. The basic premise is understanding that the TS for SelectListItem has already been processed by NTypewriter and exists in a known location. Once you can work with that assumption, then you can recognize that the type of CreativeOptions is a complex type and requires an import for it. You then output the import.

Now, for me, I am never exporting a .Net type in my API. I want more control over my api. I don't want .Net to change the definition of a class on me during an upgrade and then it forces a change to my api. c
But given that you are exporting .Net types in your API, I would suspect that data.Classes would contain those classes and you need to find a way to extract them in the for class in data.Classes.

For my builtin classes, I use an attribute on those classes that I want exported, so I can use:
for class in data.Classes | Symbols.ThatHaveAttribute "ExportToTypescript"

If you didn't want to hard code the list of classes that need to be exported in your .nt script, you might be able to do two passes over the classes.
The first pass finds all the classes you want to export and then creates a list of those classes and the classes that they use as data members.
The second pass iterates over data.Classes and matches the class name against the list. If it is found, then export it.
This sounds potentially slow, but NTypewriter is already blazingly fast on my fairly large project that maybe the speed will be ok to do two passes.

from ntypewriter.

NeVeSpl avatar NeVeSpl commented on September 22, 2024 1

I believe that question is mainly about how to get access to types defined outside of our source code, there is an option for that:
SearchInReferencedProjectsAndAssemblies

from ntypewriter.

washamdev avatar washamdev commented on September 22, 2024

Thank you both for the helpful responses!

Enabling the SearchInReferencedProjectsAndAssemblies allowed me to now search the Microsoft.AspNetCore.Mvc.Rendering namespace for SelectListItem, so thanks for that!

The remaining problem is that when I include this in my .nt template:

{{~ for dependency in class | Type.AllReferencedTypes ~}}
import {{ dependency.BareName }} = Exported.{{ dependency.FullName }};
{{~ end ~}}

For some reason, it is not detecting that my class is referencing a property that has the type Microsoft.AspNetCore.Mvc.Rendering.SelectListItem. Nothing with the name SelectListItem appears in the imports at all, so the Type.AllReferencedTypes is not finding that property type for some reason. Do you know why this would happen, and how to get it to be found with Type.AllReferencedTypes?

from ntypewriter.

NeVeSpl avatar NeVeSpl commented on September 22, 2024

Because of that line :

if (type.Namespace.StartsWith("System.") || type.Namespace.StartsWith("Microsoft.") ||

This is unfortunately by design, this function does not return types from System.* and Microsoft.* namespaces, and there is no option for changing that (yet).

from ntypewriter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.