Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public PropertyModel(
/// <summary>Gets a value indicating whether the property is nullable.</summary>
public override bool IsNullable => (_settings.GenerateOptionalPropertiesAsNullable && !_property.IsRequired) || base.IsNullable;

/// <summary>Gets a value indicating whether the property's corresponding constructor parameter should be optional.</summary>
public bool RenderOptionalCtorArgument => IsNullable && !_property.IsRequired;

/// <summary>Gets or sets a value indicating whether empty strings are allowed.</summary>
public bool AllowEmptyStrings =>
_property.ActualTypeSchema.Type.IsString() &&
Expand Down Expand Up @@ -336,4 +339,4 @@ private static string GetRangeType(string? propertyFormat) =>
_ => "double",
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
{%- assign parentProperties = "" | empty %}
{% endif %}

{%- assign sortedProperties = AllProperties | sort: "Name" %}
{%- assign sortedProperties = AllProperties | sort: "RenderOptionalCtorArgument", "Name" %}
{%- assign sortedParentProperties = parentProperties | sort: "Name" %}

{%- if UseSystemTextJson %}
[System.Text.Json.Serialization.JsonConstructor]
{%- else %}
[Newtonsoft.Json.JsonConstructor]
{%- endif %}
{% if IsAbstract %}protected{% else %}public{% endif %} {{ClassName}}({% for property in sortedProperties %}{%- if skipComma %}{%- assign skipComma = false %}{% else %}, {% endif %}{{ property.Type }} @{{ property.PropertyName | lowercamelcase }}{% endfor %})
{% if IsAbstract %}protected{% else %}public{% endif %} {{ClassName}}({% for property in sortedProperties %}{%- if skipComma %}{%- assign skipComma = false %}{% else %}, {% endif %}{{ property.Type }} @{{ property.PropertyName | lowercamelcase }}{% if property.RenderOptionalCtorArgument %} = null{% endif %}{% endfor %})
{%- assign skipComma = true %}
{%- if HasInheritance %}
: base({%- for property in sortedParentProperties %}{%- if skipComma %}{%- assign skipComma = false %}{% else %}, {% endif %}{{ property.PropertyName | lowercamelcase }}{%- endfor %})
Expand Down
Loading