/// <summary> /// Retrieves the value with the given <see cref="Id"/> if possible. Otherwise evaluates the <see cref="Code"/>. /// </summary> /// <param name="engine">Engine to execute code against</param> /// <returns>The value from evaluation of the <see cref="Code"/></returns> public virtual object GetValue(ICompositionEngine engine) { if (Id != null) { var value = engine.GetProperty(Id); if (value != null) { return(value); } } var rawCode = Code; if (engine.ShouldConvertTimeMarks()) { rawCode = new TimeConverter().ReplaceTimespans(rawCode); } return(engine.Execute(rawCode)); }
/// <summary> /// Builds a string, joined with the <see cref="Joiner"/> from each of the child <see cref="ILexigram"/> values with the the <paramref name="engine"/>. /// </summary> /// <param name="engine">The engine to execute code against</param> /// <returns>The compiled string from the engine with the composition</returns> public virtual string Build(ICompositionEngine engine) { var built = new StringBuilder(); foreach (var token in this) { var value = token.GetValue(engine); built.Append(value.ToString()); if (token is IIdLexigram) { var id = (token as IIdLexigram).Id; if (!string.IsNullOrWhiteSpace(id)) { engine.SetProperty(id, value); } } } return(string.Join(Joiner, built)); }
public virtual object GetValue(ICompositionEngine engine) => Build(engine);