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 @@ -125,7 +125,7 @@ export class CSharpRenderer extends ConvenienceRenderer {
protected nullableCSType(t: Type, follow: (t: Type) => Type = followTargetType, withIssues = false): Sourcelike {
t = followTargetType(t);
const csType = this.csType(t, follow, withIssues);
if (isValueType(t)) {
if (isValueType(t) || this._csOptions.version >= 8) {
return [csType, "?"];
} else {
return csType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,13 @@ export class SystemTextJsonCSharpRenderer extends CSharpRenderer {
const isNullable = followTargetType(property.type).isNullable;
const isOptional = property.isOptional;

if (isOptional && !isNullable) {
if (!isOptional) {
attributes.push(["[", "JsonRequired", "]"]);
} else if (isOptional && !isNullable) {
attributes.push(["[", "JsonIgnore", "(Condition = JsonIgnoreCondition.WhenWritingNull)]"]);
}


// const requiredClass = this._options.dense ? "R" : "Required";
// const nullValueHandlingClass = this._options.dense ? "N" : "NullValueHandling";
// const nullValueHandling = isOptional && !isNullable ? [", NullValueHandling = ", nullValueHandlingClass, ".Ignore"] : [];
Expand Down
5 changes: 3 additions & 2 deletions packages/quicktype-core/src/language/CSharp/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum Framework {
SystemTextJson = "SystemTextJson"
}

export type Version = 5 | 6;
export type Version = 5 | 6 | 8;
export interface OutputFeatures {
attributes: boolean;
helpers: boolean;
Expand Down Expand Up @@ -55,7 +55,8 @@ export const cSharpOptions = {
"C# version",
[
["5", 5],
["6", 6]
["6", 6],
["8", 8]
],
"6",
"secondary"
Expand Down