How to write template whether certain ExtraProperty is defined / has certain value #166
-
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? |
Beta Was this translation helpful? Give feedback.
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:
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
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: