Skip to content

Commit 07dbc6a

Browse files
committed
Add support for CSharpField.DynamicInitValue
1 parent 6dbf182 commit 07dbc6a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/CppAst.CodeGen/CSharp/CSharpField.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public CSharpField(string name)
3232

3333
public string? InitValue { get; set; }
3434

35+
public Func<string>? DynamicInitValue { get; set; }
36+
3537
/// <inheritdoc />
3638
public string Name { get; set; }
3739

@@ -67,6 +69,12 @@ public override void DumpTo(CodeWriter writer)
6769
writer.Write(" = ");
6870
writer.Write(InitValue);
6971
}
72+
else if (DynamicInitValue != null)
73+
{
74+
writer.Write(" = ");
75+
writer.Write(DynamicInitValue());
76+
}
77+
7078
writer.Write(";");
7179
writer.WriteLine();
7280
}

src/CppAst.CodeGen/CSharp/Plugins/DefaultEnumItemConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Register(CSharpConverter converter, CSharpConverterPipeline pipeline
4545
Modifiers = CSharpModifiers.Const,
4646
FieldType = csEnum,
4747
Comment = csEnumItem.Comment,
48-
InitValue = $"{csEnum.Name}.{csEnumItem.Name}"
48+
DynamicInitValue = () => $"{csEnum.Name}.{csEnumItem.Name}"
4949
};
5050
converter.ApplyDefaultVisibility(csEnumItemAsField, csClass);
5151

0 commit comments

Comments
 (0)