How to write template whether certain ExtraProperty is defined / has certain value #166
Answered
by
k-nishizaki
k-nishizaki
asked this question in
Q&A
|
I want to know how to write template to check an item of ExtraProperties is defined or has certain value. The only way I've found is the following, but it is ugly and cannot write else condition. Is there any better way? |
Answered by
k-nishizaki
Dec 27, 2022
Replies: 2 comments
|
Finally I found that CustomProperties works with lookup in an expression. public class TestConfigEditor : IConfigEditor
{
public Task AfterPrepareAsync(IRootConfig config)
{
var cgc = (CodeGenConfig)config;
foreach (var e in cgc.Entities)
{
foreach (var name in new string[] { "someKey", "anotherKey" })
{
bool exists = e.ExtraProperties?.ContainsKey(name) ?? false;
e.CustomProperties[$"{name}Exists"] = exists;
e.CustomProperties[name] = exists ? e.GetExtraProperty<JValue>(name).Value : null;
}
}
}
}After storing the value in CustomProperties, you can use the value in the template: |
0 replies
Answer selected by
k-nishizaki
|
I found another solution. then, you can use the two functions hasKey and valueOf in your template: I've tested the two functions against ExtraProperties and CustomProperties. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally I found that CustomProperties works with lookup in an expression.
The following is the sample:
After storing the value in CustomProperties, you can use the value in the template: