public override (object Value, string Error) TryGetValue(object data)
        {
            if (this.Value != null && this.Value is string val)
            {
                // value is a string (not an expression) should be interpreted as string, which means interperlated
                return(lg.Evaluate(val, data).ToString(), null);
            }

            return(base.TryGetValue(data));
        }
Esempio n. 2
0
        public override (string Value, string Error) TryGetValue(object data)
        {
            if (this.Value != null)
            {
                // interpolated string
                return(lg.Evaluate(this.Value, data).ToString(), null);
            }

            return(base.TryGetValue(data));
        }
        /// <summary>
        /// Method to generate text from given template and data.
        /// </summary>
        /// <param name="turnContext">Context for the current turn of conversation.</param>
        /// <param name="template">template to evaluate.</param>
        /// <param name="data">data to bind to.</param>
        /// <returns>generated text.</returns>
        public async Task <string> Generate(ITurnContext turnContext, string template, object data)
        {
            try
            {
                return(await Task.FromResult(lgFile.Evaluate(template, data).ToString()));
            }
            catch (Exception err)
            {
                if (!string.IsNullOrEmpty(this.Id))
                {
                    throw new Exception($"{Id}:{err.Message}");
                }

                throw;
            }
        }