Skip to content

Commit

Permalink
configurable fieldname
Browse files Browse the repository at this point in the history
  • Loading branch information
chenrong committed Sep 26, 2024
1 parent 9bf8f69 commit 530b0f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit 530b0f3

Please sign in to comment.