Comments (3)
Ok, I think I have figured it out.
IType is a symbol and as such, I can assume that it has an attributes array and do a filter on it.
I have created a function like this:
{{- func typeName(type)
useType = Type.Unwrap(type)
if (useType.ArrayType != null)
useType = useType.ArrayType
end
typeAttrs = useType.Attributes | Array.Filter @AttrIsTypescriptType
if (typeAttrs.size > 0)
ret typeAttrs[0] | Custom.ExtractTypescriptType;
end
ret useType | Type.ToTypeScriptType
end
}}
{{- func AttrIsTypescriptType(attr)
ret attr.Name | String.Contains "TypescriptType"
end
}}
first, I nwrap the type and extract the actual type if the type is an array type.
Then, I search the list of attributes for the symbol to find the TypescriptType attribute and if it exists, I use a custom c# function to extract the attributes parameter, which is it's name.
If the symbol doesn't have the TypescriptType attribute, I just return the Type.ToTypescriptType.
This seems to work well. I now just need to figure out how to do this on the parameter array.
from ntypewriter.
It looks like you are getting there, but I really do not know why you prefer to do it in scriban instead of C#.
from ntypewriter.
Hmm, that is a good point. I hadn't thought of doing it in C#. In my mind, the NTypewriter scripts are scriban and I was just locked into "do it in scriban". I will have to re-evaluate it. I think I could really simplify the scripts, and introduce better reuse if I did more in C#.
Thanks for the suggestion!
from ntypewriter.
Related Issues (20)
- Is NTypewriter.SourceGenerator intended to add rendered templates to compilation source? HOT 4
- How to convert .NET classes to TypeScript? HOT 4
- Attributes generate values that are region dependent HOT 3
- Dynamic property throws error
- IEnumValue should implement ISymbolBase HOT 5
- Allow to use Regex (from System.Text.RegularExpressions) in .nt.cs files HOT 1
- Enum Attribute arguments are stored as Type Object HOT 5
- AttributeArgument with null value, TypedConstant ToString throws NullReferenceException HOT 1
- extracting argument from attribute now fails HOT 5
- Action.ReturnType has is broken with introduction of TypedConstant. HOT 6
- FR: please include the vsix package file in the list of assets for the release. HOT 2
- AttributeArgument.Value is not always ITypedConstant or ITypedConstant[] HOT 4
- AttributeArgument.Value.Tostring() causes exception: TypedConstant is an array. Use Values property
- Unable to build project with SourceGenerator: 'ITypedConstant' could not be found HOT 2
- Unable to debug SourceGenerator, no output and no log files created HOT 6
- Why does Type.ToTypeScriptType ignore nullable if [Required] attribute is present? HOT 4
- Template processing fails when reading arguments from an Attribute that has arguments with default values (Roslyn project) HOT 3
- Missing default value for DateTime
- Incremental Generator HOT 1
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.