Skip to content
Merged
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 @@ -164,5 +164,11 @@ public CSharpGeneratorSettings()

/// <summary>Generate C# 9.0 record types instead of record-like classes.</summary>
public bool GenerateNativeRecords { get; set; }

/// <summary>
/// The prefix appended when generating a field based on the property name. Default is "_";
/// </summary>
public string FieldNamePrefix { get; set; } = "_";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NJsonSchema.Annotations;
using System.Globalization;
using NJsonSchema.CodeGeneration.Models;
using System.Runtime;

namespace NJsonSchema.CodeGeneration.CSharp.Models
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public PropertyModel(
public string? Description => _property.Description;

/// <summary>Gets the name of the field.</summary>
public string FieldName => "_" + ConversionUtilities.ConvertToLowerCamelCase(PropertyName, true);
public string FieldName => _settings.FieldNamePrefix + ConversionUtilities.ConvertToLowerCamelCase(PropertyName, true);

/// <summary>Gets a value indicating whether the property is nullable.</summary>
public override bool IsNullable => (_settings.GenerateOptionalPropertiesAsNullable && !_property.IsRequired) || base.IsNullable;
Expand Down
Loading