Comments (4)
Hi @dodyg, could you please provide some more details about this? An example would be nice.
from typewriter.
How can I generate
interface Person {
Name? : string
Age? : string
}
from typewriter.
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.
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)
- Integration with CI/CD pipeline HOT 1
- Square brackets added to nullable string HOT 10
- IsNullable == false for nullable reference types HOT 1
- It's time to rewrite all TypeWriter project HOT 6
- Did typewriter stop working in VS 16.7.0? HOT 3
- Typewriter Extension is not working anymore HOT 3
- Angular service with multiple response types (ASP.NET CORE) HOT 1
- $Classes cannot find record classes HOT 13
- Typewriter 2.0 is almost here... HOT 3
- .NET 5: Model not generated if library is a dependency HOT 4
- .NET 5: File nesting not working for generated .ts files in Visual Studio HOT 1
- VS 2022 Preview compatible version unofficial release HOT 9
- IsAbstract has no documentation
- Typewriter does not seem to be compatible with the latest version of C# 10. HOT 3
- Wrong Property.Type.IsGeneric value in case of primitive[] array HOT 3
- Does Typewriter work with ActionResult ? HOT 1
- Typewriter version for visual studio mac
- Is this project
- Is this project Active HOT 3
- Is this project active? Can we update for VS2022? HOT 2
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 typewriter.