Code Monkey home page Code Monkey logo

Comments (4)

frhagn avatar frhagn commented on August 16, 2024

Hi @dodyg, could you please provide some more details about this? An example would be nice.

from typewriter.

dodyg avatar dodyg commented on August 16, 2024

How can I generate

interface Person {
  Name? : string
  Age? : string
}

from typewriter.

frhagn avatar frhagn commented on August 16, 2024

If you want it on all properties, just add the question mark in the template like this:

$Classes(*Models*)[
interface $Name { $Properties[
    $Name?: $Type;]
}]

Otherwise the problem is how to determine which properties should be decorated. One solution is to use attributes to mark optional properties in your c# classes e.g:

${
    var IsOptional = (Property p) => p.Attributes.Any(a => a.Name == "Optional");
}
$Classes(*Models*)[
interface $Name { $Properties[
    $Name$IsOptional[?]: $Type;]
}]
public class Person
{
    [Optional]
    public string Name { get; set; }
    public int Age { get; set; }
}

from typewriter.

dodyg avatar dodyg commented on August 16, 2024

This is exactly what I need. Thank you so much. I just created a dummy Optional attribute and tag the necessary properties with it

[AttributeUsage(AttributeTargets.All)]
public class OptionalAttribute : Attribute
{
}

from typewriter.

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.