Comments (4)
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.
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.
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.
Because of that line :
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)
- Changes from GIT not picked up by NTypewriter HOT 3
- This is perfect for AI
- Failed to compile user code (System.Collections) HOT 10
- Source Generator ArgumentNullException HOT 8
- Save function is misleading HOT 3
- `Microsoft.CodeAnalysis` not found HOT 10
- SourceGenerator can't find dependent projects HOT 2
- Publish latest releases as NuGet package HOT 4
- Template output preview is always displayed on top of everything HOT 1
- Template output preview with dark mode support
- Using C# 9.0 init accessors in a custom function gives an error inside Visual Studio extension HOT 1
- Extend AllReferencedTypes to search on Interfaces HOT 1
- Request - Property internal set vs public flag or filter HOT 3
- Action.Url does not support array-valued parameters HOT 1
- How to use builtin function LINQ.Where in template? HOT 7
- error while generating typescript services from ntypewriter runtime generator HOT 2
- Generic class with itself as argument of base type equality problem HOT 3
- How to join arrays without losing type information? HOT 2
- How to automatically render templates? HOT 2
- Suggestion: Use generic types for functions provided in SymbolsFunctions (and others)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ntypewriter.