Пример #1
0
        private string ExecuteFunction(TagModel model, DefineFunctionTag.FunctionDefinition function)
        {
            var callArguments = new Dictionary <string, object>();
            var freeFields    = FreeFields(model);

            foreach (var argumentWithDefault in function.Arguments)
            {
                var argument    = argumentWithDefault;
                var defaultPath = null as string;
                if (argumentWithDefault.Contains("(") && argumentWithDefault.EndsWith(")"))
                {
                    var split = argumentWithDefault.IndexOf("(", StringComparison.InvariantCulture);
                    argument    = argumentWithDefault.Substring(0, split);
                    defaultPath = argumentWithDefault.Substring(split + 1, argumentWithDefault.Length - split - 2);
                    // Console.WriteLine(defaultPath);
                }
                var value = CollectionUtils.SafeGet(freeFields, argument) ?? CollectionUtils.SafeGet(freeFields, LanguageHelper.CamelCaseProperty(argument));
                if (!string.IsNullOrEmpty(defaultPath) && value == null)
                {
                    value = model.TryGet(defaultPath);
                }
                if (function.IsStrict && value == null)
                {
                    throw MacroException.NullNotAllowed(argument).Decorate(Name.Context);
                }
                callArguments[argument] = value;
//                model.Tag[argument] = value;
            }
            model.PushTagStack();
            foreach (var argument in callArguments)
            {
                model.Tag[argument.Key] = argument.Value;
            }
            var result = function.Evaluate(model);

            model.PopTagStack();
            return(TypeConverter.To <string>(result));
        }