コード例 #1
0
        private Func <IReadOnlyList <object>, object> FromFile()
        => (IReadOnlyList <object> args) =>
        {
            var filePath = args[0].ToString().NormalizePath();

            var resourcePath  = GetResourcePath(filePath);
            var stringContent = File.ReadAllText(resourcePath);

            var newScope     = evaluationTargetStack.Count == 0 ? null : CurrentTarget().Scope;
            var newTemplates = new Templates(templates: Templates, expressionParser: expressionParser);
            return(newTemplates.EvaluateText(stringContent, newScope, lgOptions));
        };
コード例 #2
0
ファイル: Expander.cs プロジェクト: marodev/botbuilder-dotnet
        private Func <IReadOnlyList <object>, object> FromFile()
        => (IReadOnlyList <object> args) =>
        {
            var filePath     = args[0].ToString().NormalizePath();
            var resourcePath = GetResourcePath(filePath);
            var format       = Evaluator.FileFormat.Evaluated;
            if (args.Count > 1)
            {
                foreach (Evaluator.FileFormat item in Enum.GetValues(typeof(Evaluator.FileFormat)))
                {
                    if (args[1].ToString().Equals(item.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        format = item;
                        break;
                    }
                }
            }

            object result;
            if (format == Evaluator.FileFormat.Binary)
            {
                result = File.ReadAllBytes(resourcePath);
            }
            else if (format == Evaluator.FileFormat.Raw)
            {
                result = File.ReadAllText(resourcePath);
            }
            else
            {
                var stringContent = File.ReadAllText(resourcePath);
                var newScope      = _evaluationTargetStack.Count == 0 ? null : CurrentTarget().Scope;
                var newTemplates  = new Templates(templates: Templates.AllTemplates, expressionParser: Templates.ExpressionParser, namedReferences: Templates.NamedReferences);
                result = newTemplates.EvaluateText(stringContent, newScope, _lgOptions);
            }

            return(result);
        };