Example #1
0
 /// <summary>
 /// 模板上下文
 /// </summary>
 /// <param name="data">数据</param>
 public TemplateContext(VariableScope data)
 {
     if (data == null)
     {
         throw new ArgumentException("data");
     };
     this._variableScope = data;
     this._errors = new List<System.Exception>();
     this._currentPath = null;
     this._charset = Encoding.Default;
     this._throwErrors = true;
     this._stripWhiteSpace = false;
 }
        public static Object Eval(VariableScope container, String expression)
        {
            String[] expressionParts = expression.Split(_expressionPartSeparator);
            if (expressionParts.Length > 0)
            {
                if (expressionParts.Length==1)
                {
                    return container[expressionParts[0]];
                }
                return Eval(container[expressionParts[0]], expressionParts, 1, expressionParts.Length);
            }

            return null;
        }
Example #3
0
        /// <summary>
        /// 模板上下文
        /// </summary>
        /// <param name="data">数据</param>
        public TemplateContext(VariableScope data)
        {
            if (data == null)
            {
                throw new ArgumentException("\"data\" cannot be null.");
            };
            String charset;
            this._variableScope = data;
            this._errors = new List<System.Exception>();
            this._currentPath = null;
            this._throwErrors = Common.Utility.ToBoolean(Engine.GetEnvironmentVariable("ThrowErrors"));
            this._stripWhiteSpace = Common.Utility.ToBoolean(Engine.GetEnvironmentVariable("StripWhiteSpace"));
            if (String.IsNullOrEmpty(charset = Engine.GetEnvironmentVariable("Charset")))
            {
                this._charset = Encoding.UTF8;
            }
            else
            {
                this._charset = Encoding.GetEncoding(charset);
            }

        }
Example #4
0
 /// <summary>
 /// ContextBase 
 /// </summary>
 public ContextBase()
 {
     variableScope = new VariableScope();
 }
Example #5
0
 /// <summary>
 /// VariableScope
 /// </summary>
 public VariableScope(VariableScope parent)
 {
     this._parent = parent;
     this._dic = new Dictionary<String, Object>(Engine.Runtime.ComparerIgnoreCase);
 }
Example #6
0
 /// <summary>
 /// VariableScope
 /// </summary>
 public VariableScope(VariableScope parent)
 {
     this.parent = parent;
     this.dic    = new Dictionary <String, Object>(StringComparer.InvariantCultureIgnoreCase);
 }
Example #7
0
 /// <summary>
 /// VariableScope
 /// </summary>
 public VariableScope(VariableScope parent)
 {
     this.parent = parent;
     this.dic = new Dictionary<String, Object>(StringComparer.InvariantCultureIgnoreCase);
 }
Example #8
0
 /// <summary>
 /// 以父VariableScope来初始化对象
 /// </summary>
 /// <param name="parent">父VariableScope</param>
 public VariableScope(VariableScope parent) :
     this(parent, null)
 {
 }
Example #9
0
 /// <summary>
 /// 以父VariableScope与字典来初始化对象
 /// </summary>
 /// <param name="parent">父VariableScope</param>
 /// <param name="dictionary">初始化字典</param>
 public VariableScope(VariableScope parent, IDictionary <String, Object> dictionary)
 {
     this._parent = parent;
     this._dic    = dictionary ?? new Dictionary <String, Object>(Engine.ComparerIgnoreCase);
 }
Example #10
0
 /// <summary>
 /// 引擎配置
 /// </summary>
 /// <param name="conf">配置内容</param>
 /// <param name="scope">初始化全局数据</param>
 public static void Configure(ConfigBase conf, VariableScope scope)
 {
     if (conf == null)
     {
         throw new ArgumentNullException("\"conf\" cannot be null.");
     }
     Configure(conf.ToDictionary(),
         conf.ResourceDirectories,
         conf.TagParsers, scope);
 }
Example #11
0
        /// <summary>
        /// 引擎配置
        /// </summary>
        /// <param name="directories">模板目录,默认为当前程序目录</param>
        /// <param name="parsers">解析器,可空</param>
        /// <param name="conf">配置参数</param>
        /// <param name="scope">全局数据,可空</param>
        public static void Configure(
            IDictionary<String, String> conf,
            String[] directories,
            String[] parsers,
            VariableScope scope)
        {
            if (conf == null)
            {
                throw new ArgumentNullException("\"conf\" cannot be null.");
            }

            _scope = scope;

            InitializationEnvironment(conf);

            if (_cache != null)
            {
                _cache.Dispose();
            }
            _cache = null;
            if (!String.IsNullOrEmpty(GetEnvironmentVariable("CachingProvider")))
            {
                Type cacheType = Type.GetType(GetEnvironmentVariable("CachingProvider"));
                _cache = (ICache)Activator.CreateInstance(cacheType);
            }

            if (Common.Utility.ToBoolean(GetEnvironmentVariable("IgnoreCase")))
            {
                _bindingFlags = BindingFlags.IgnoreCase;
                _stringComparer = StringComparer.OrdinalIgnoreCase;
                _stringComparison = StringComparison.OrdinalIgnoreCase;
            }
            else
            {
                _stringComparison = StringComparison.Ordinal;
                _bindingFlags = BindingFlags.DeclaredOnly;
                _stringComparer = StringComparer.Ordinal;
            }
            if (directories == null)
            {
                _resourceDirectories = new String[] {
                    //Environment.CurrentDirectory
                };
            }
            else
            {
                _resourceDirectories = directories;
            }
            InitializationParser(parsers);
        }
Example #12
0
 /// <summary>
 /// 以父VariableScope来初始化对象
 /// </summary>
 /// <param name="parent">父VariableScope</param>
 public VariableScope(VariableScope parent)
     : this(parent, null)
 {
 }
Example #13
0
 /// <summary>
 /// 以父VariableScope与字典来初始化对象
 /// </summary>
 /// <param name="parent">父VariableScope</param>
 /// <param name="dictionary">初始化字典</param>
 public VariableScope(VariableScope parent, IDictionary<String, Object> dictionary)
 {
     this._parent = parent;
     this._dic = dictionary ?? new Dictionary<String, Object>(Engine.ComparerIgnoreCase);
 }
Example #14
0
 public VariableScope Copy()
 {
     VariableScope owen = new VariableScope(this.Parent);
     foreach (KeyValuePair<String, Object> value in this._dictionary)
     {
         owen[value.Key] = value.Value;
     }
     return owen;
 }