Coder Social home page Coder Social logo

Comments (13)

jburzynski avatar jburzynski commented on August 18, 2024

Hi! Can you give an example? Do you mean providing a "global" default value for all properties?

from typegen.

schneiderpat avatar schneiderpat commented on August 18, 2024

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.

jburzynski avatar jburzynski commented on August 18, 2024

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.

schneiderpat avatar schneiderpat commented on August 18, 2024

Thanks a lot :)

Greets!

from typegen.

jburzynski avatar jburzynski commented on August 18, 2024

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.

schneiderpat avatar schneiderpat commented on August 18, 2024

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.

schneiderpat avatar schneiderpat commented on August 18, 2024

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.

jburzynski avatar jburzynski commented on August 18, 2024

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.

schneiderpat avatar schneiderpat commented on August 18, 2024

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.

jburzynski avatar jburzynski commented on August 18, 2024

You're welcome! Thanks!

I'll let you know when it's implemented.

from typegen.

jburzynski avatar jburzynski commented on August 18, 2024

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.

schneiderpat avatar schneiderpat commented on August 18, 2024

I tested and it works awesome!
I´m waiting for the official release ;)

Thanks again for your great work!

from typegen.

jburzynski avatar jburzynski commented on August 18, 2024

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)

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.