Skip to content

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
Discussion options

You must be logged in to vote

Finally I found that CustomProperties works with lookup in an expression.
The following is the sample:

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:

Custom existance…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by k-nishizaki
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant