예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="options"></param>
        public TextFormatter(string pattern, TextTemplateOptions options)
        {
            if (string.IsNullOrEmpty(pattern))
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            var extend = (options & TextTemplateOptions.NotAllowNullValue) !=
                         TextTemplateOptions.NotAllowNullValue;

            if ((options & TextTemplateOptions.Compiled) == TextTemplateOptions.Compiled)
            {
                if (!SectionDict.TryGetValue(pattern, out var array))
                {
                    lock (SectionDict)
                    {
                        if (!SectionDict.TryGetValue(pattern, out array))
                        {
                            array = LoadSections(pattern, extend);
                            SectionDict[pattern] = array;
                        }
                    }
                }

                sectionList = array;
            }
            else
            {
                sectionList = LoadSections(pattern, extend);
            }

            notAllowNullValue = (options & TextTemplateOptions.NotAllowNullValue) ==
                                TextTemplateOptions.NotAllowNullValue;
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="options"></param>
        public TextFormatter(string pattern, TextTemplateOptions options)
        {
            if (string.IsNullOrEmpty(pattern))
            {
                throw new ArgumentNullException(nameof(pattern));
            }
            this.options = options;
            bool extend = (this.options & TextTemplateOptions.NotAllowNullValue) != TextTemplateOptions.Compiled;

            if ((this.options & TextTemplateOptions.Compiled) == TextTemplateOptions.Compiled)
            {
                if (!SectionDict.TryGetValue(pattern, out Section[] array))
예제 #3
0
        /// <summary>
        /// Format
        /// </summary>
        /// <param name="pattern"></param>
        /// <param name="obj"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static string Format(string pattern, object obj, TextTemplateOptions options)
        {
            TextFormatter template = new TextFormatter(pattern, options);

            return(template.Format(obj));
        }