Skip to content

[Question] Is it possible to output a property's default value? #128

@rmarskell

Description

@rmarskell

Hey there, I'm looking to integrate NTypewriter (source generator) into a new project and so far I'm loving the capabilities. A previous project I worked on used TypeGen and while it was good for simplicity, there was no real control over the templates. I've been able to replicate all of the functionality of TypeGen with NTypewriter, except one big thing (default values) and I'm hoping I'm just missing something/not searching the correct terms.

Basically, given the following C# classes...

using System.Collections.Generic;

public class NameCountClass {
  public string Name { get; set; }
  public int Count { get; set; }
}

public static class StaticClass {
  public static string StaticProperty => "Test";

  public static Dictionary<string, NameCountClass> NameCounts = new Dictionary<string, NameCountClass>() {
    { "a", new NameCountClass() { Name = "A name", Count = 123 } },
    { "b", new NameCountClass() { Name = "B name", Count = 321 } }
  };
}

...is it possible to output the default values in a TS class something like this:

export class StaticClass {
  static StaticProperty: string = "Test";
  static NameCounts: { [key: string]: NameCountClass } = {"a":{"Name":"A name", "Count": 123}, "b":{"Name":"B name", "Count": 321}}
}

Basically, is there a way to access the default values for properties to output them?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions