Exemplo n.º 1
0
        private static (string[] nameSemgents, string parameters) SplitToSegmentsAndParameters(
            this string token,
            PlaceholderConfig placeholderConfig,
            ITemplateConfig templateConfig,
            bool isOpen)
        {
            var prefixLength = placeholderConfig.Start.Length;

            if (!isOpen)
            {
                prefixLength += templateConfig.ClosePrefix.Length;
            }
            var suffixLength = placeholderConfig.End.Length;

            if (isOpen)
            {
                suffixLength += templateConfig.OpenSuffix.Length;
            }

            var(name, parameters) = token
                                    .Cut(prefixLength, suffixLength)
                                    .SplitBy(placeholderConfig.ParametersDelimiter);

            var segments = name.Split(placeholderConfig.NamesDelimiter);

            return(segments, parameters);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 模板上下文
        /// </summary>
        /// <param name="config">模板配值</param>
        /// <param name="data">数据</param>
        public TemplateContext(ITemplateConfig config, VariableScope data)
        {
            if (config == null)
            {
                throw new ArgumentException("config");
            }

            if (data == null)
            {
                throw new ArgumentException("data");
            }
            this.Charset         = System.Text.Encoding.Default;
            this.ThrowExceptions = true;
            this.config          = config;
            this.variableScope   = data;
        }