Comments (13)
Hi! Can you give an example? Do you mean providing a "global" default value for all properties?
from typegen.
Currently we have to to this:
[TSDefaultValue("")]
public string FirstName { get; set; }
[TSDefaultValue("")]
public string LastName { get; set; }
We need to generate the classes with default values because we have another generator to create formgroups in an angular in a special way.
A global Setting to generate default values for specific types would be awesome.
from typegen.
This seems like a useful feature for some cases. I'll aim to add it in the next release (the next release will also have the fix to #33).
I'll keep you updated with any progress in this topic. Cheers!
from typegen.
Thanks a lot :)
Greets!
from typegen.
I updated the NuGet packages in the dev branch (both regular and .NET CLI tool; nuget
and nuget-dotnetcli
folders). They now contain the functionality to generate empty values for the specified TypeScript types. You would use it like this in tgconfig.json
(there's also a corresponding option in GenerationOptions
):
{
"generateEmptyValues": [ "string", "number", ... ]
}
Can you please check if it works properly in your case? I'd like to make sure it works before releasing. Thanks
from typegen.
How can I install the nuget-dotnetcli tool to test it?
I tested the NuGet package. If we have nullable type. Is it possible to set the default value to null?
But so far awesome job!!
from typegen.
An option with custom default mappings would solve the problem and would be very flexiable.
// tgconfig.json
{
"emptyValueMappings: {
"Date | null": "null",
"number": "-1"
}
}
And in your EmptyValue.cs
you check for that option and iterate through them first. By checking them first you add the possibility to override your defaults.
from typegen.
You can download the TypeGen.DotNetCli
package from NuGet and then specify custom source when installing the tool:
dotnet tool install TypeGen.DotNetCli -g --add-source "PACKAGE_FOLDER_PATH"
I've dropped support for per-project tools, because they are going to be abandoned by Microsoft anyway (I gave a more detailed 'rationale' for dropping per-project tools in this post), so right now TypeGen.DotNetCli is only a global tool.
About empty values, I'm thinking about removing the option that exists right now (generateEmptyValues
) and replacing it with the option you suggested. I think there is no need for an additional option, if there's already an option to specify values for types. Do you think this would be ok?
from typegen.
You are right, an additional option is not necessary.
Removing generateEmptyValues
is ok, when we can specify default values ourselves.
Thanks again for your work!
from typegen.
You're welcome! Thanks!
I'll let you know when it's implemented.
from typegen.
There is a new version on the dev branch (nuget package). The option is named defaultValuesForTypes
and you would use it like this (the same as in your post):
"defaultValuesForTypes": {
"number": "-1",
"Date | null": "null"
}
It would be cool if you could check again if it works! Thanks! :)
from typegen.
I tested and it works awesome!
I´m waiting for the official release ;)
Thanks again for your great work!
from typegen.
No problem! Thanks for the info!
I've released version 2.0.1 (major version change is because of the changed syntax in the TypeGen
nuget package - it's now the same as in the .NET CLI tool) and it contains the new functionality (usage is exactly the same). Hope it works! :)
from typegen.
Related Issues (20)
- Typegen generating class files and enums I don't have in my code base HOT 2
- UseDefaultExport breaks interface inheritance HOT 3
- IgnoreBase()/TsIgnoreBaseAttribute doesn't work with interfaces HOT 4
- Supporting comments? HOT 3
- Concurrent "dotnet tool restore" fails, DotnetToolSettings.xml is being used by another process
- Specify TypeScript namespace
- Built in types HOT 1
- TsContentGenerator > GetMemberValueText > JsonConvert.SerializeObject HOT 1
- APPLICATION ERROR: Generated type must be either a C# class or enum. Error when generating type System.RuntimeMethodHandle HOT 2
- .NET 7 support HOT 3
- Not able to install with Nuget on <TargetFramework>net6.0-windows</TargetFramework> HOT 5
- Cannot generate generic base class as TypeScript interface HOT 1
- Static Class
- Could not resolve assembly: Microsoft.AspNetCore.Mvc.Core, Version=5.0.0.0
- Non primitive default values that get serialized as JSON do not match the property name casing of the generated files HOT 3
- Make "bin" directory configurable HOT 2
- GenerationSpecs is slow HOT 2
- Can we have a on after Generation overridable method? HOT 1
- Change the way release notes are published HOT 2
- Type 'TypeScriptGenSpec' not found in TypeGen.Core or any of the assemblies 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 typegen.