Skip to content
Merged
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
24 changes: 23 additions & 1 deletion src/CodeGenHelpers/PropertyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ internal enum FieldType
private string _value;
private string _safeValue;
private bool _getOnly;
private bool _virtual;
private bool _override;
private Accessibility? _setterAccessibility;
private readonly List<string> _attributes = new List<string>();
private readonly DocumentationComment _xmlDoc = new DocumentationComment();
Expand Down Expand Up @@ -114,6 +116,12 @@ public PropertyBuilder WithAccessModifier(Accessibility accessModifier)
AccessModifier = accessModifier;
return this;
}

public PropertyBuilder Override(bool @override = true)
{
_override = true;
return this;
}

public PropertyBuilder MakeStatic()
{
Expand All @@ -122,6 +130,12 @@ public PropertyBuilder MakeStatic()
return this;
}

public PropertyBuilder MakeVirtualProperty()
{
_virtual = true;
return this;
}

public PropertyBuilder AddAttribute(string attribute)
{
var sanitized = attribute.Replace("[", string.Empty).Replace("]", string.Empty);
Expand Down Expand Up @@ -216,11 +230,19 @@ void IBuilder.Write(ref CodeWriter writer)

var type = Type.Trim();
var name = Name.Trim();
string additionalModifier = null;
if (_virtual)
additionalModifier = "virtual";
else if (_override)
additionalModifier = "override";

var output = (FieldTypeValue switch
{
FieldType.Const => $"{AccessModifier.Code()} const {type} {name}",
FieldType.ReadOnly => $"{AccessModifier.Code()} readonly {type} {name}",
_ => $"{AccessModifier.Code()} {type} {name}"
_ => additionalModifier is null
? $"{AccessModifier.Code()} {type} {name}"
: $"{AccessModifier.Code()} {additionalModifier} {type} {name}"
}).Trim();

if(FieldTypeValue != FieldType.Property)
Expand Down