コード例 #1
0
ファイル: WithTagParser.cs プロジェクト: stlimtat/arlo-test
        internal static WithTagParser getInstance()
        {
            if (_instance == null)
            {
                _instance = new WithTagParser();
                WithTagParser.tagSplitterTemplateEngine = new TagSplitterTemplateEngine();
                List <IMyParser> myTagParsers = new List <IMyParser>();
                // Usually I will use dependency injection to run this initialization
                // But in this case, I leave it to the constructor
                IMyParser parser = null;
                // the end with tag parser
                parser = EndWithTagParser.getInstance();
                myTagParsers.Add(parser);

                // the With tag parser
                parser = WithTagParser._instance;
                myTagParsers.Add(parser);

                // the composite tag parser
                parser = CompositeTagParser.getInstance();
                myTagParsers.Add(parser);

                // the dataSource simple tag parser
                parser = BasicTagParser.getInstance();
                myTagParsers.Add(parser);
                // the C# expression language tag parser

                WithTagParser.tagSplitterTemplateEngine.MyTagParsers = myTagParsers;
            }
            return(_instance);
        }
コード例 #2
0
        /// <summary>
        /// Applies the specified datasource to a string template, and returns a result string
        /// with substituted values.
        /// </summary>
        public string Apply(string template, object dataSource)
        {
            string result = null;

            TagSplitterTemplateEngine tagSplitterTemplateEngine = new TagSplitterTemplateEngine();

            tagSplitterTemplateEngine.MyTagParsers = this.myTagParsers;

            IDictionary <string, object> dataSourceDict = new RouteValueDictionary(dataSource);

            result = tagSplitterTemplateEngine.Apply(template, dataSourceDict);

            return(result);
        }