示例#1
0
        private static object FuncFilter(object[] args)
        {
            if (!_mnr.CheckArgCount(2, "filter", args))
            {
                return(null);
            }

            object list = args[0];

            string property;

            property = args[1].ToString();

            if (!(list is IEnumerable))
            {
                throw new TmplException("argument 1 of filter has to be IEnumerable", 0, 0);
            }

            IEnumerator   ienum   = ((IEnumerable)list).GetEnumerator();
            List <object> newList = new List <object>();

            while (ienum.MoveNext())
            {
                object val = TmplManager.ProcessProperty(ienum.Current, property);

                if (val is bool && (bool)val)
                {
                    newList.Add(ienum.Current);
                }
            }

            return(newList);
        }
示例#2
0
        public string Evaluate(string expression)
        {
            TmplManager  Tmpl   = TmplManager.Parser("${" + expression + "}");
            StringWriter writer = new StringWriter();

            Tmpl.Process(writer);
            return(writer.ToString());
        }
示例#3
0
        private static object FuncJoin(object[] args)
        {
            if (!_mnr.CheckArgCount(2, 3, "join", args))
            {
                return(null);
            }

            object list = args[0];

            string property;
            string delim;

            if (args.Length == 3)
            {
                property = args[1].ToString();
                delim    = args[2].ToString();
            }
            else
            {
                property = string.Empty;
                delim    = args[1].ToString();
            }

            if (!(list is IEnumerable))
            {
                throw new TmplException("argument 1 of join has to be IEnumerable", 0, 0);
            }

            IEnumerator   ienum = ((IEnumerable)list).GetEnumerator();
            StringBuilder sb    = new StringBuilder();
            int           index = 0;

            while (ienum.MoveNext())
            {
                if (index > 0)
                {
                    sb.Append(delim);
                }

                if (args.Length == 2)   // do not evalulate property
                {
                    sb.Append(ienum.Current);
                }
                else
                {
                    sb.Append(TmplManager.ProcessProperty(ienum.Current, property));
                }

                index++;
            }

            return(sb.ToString());
        }
示例#4
0
        public static void Register(TmplManager mn, Templates _tpl)
        {
            _mnr       = mn;
            _Templates = _tpl;

            _mnr.RegisterFunction("contains", FuncContains);
            _mnr.RegisterFunction("isnullorempty", FuncIsNullOrEmpty);
            _mnr.RegisterFunction("isnotempty", FuncIsNotEmpty);
            _mnr.RegisterFunction("isnumber", FuncIsNumber);
            _mnr.RegisterFunction("toupper", FuncToUpper);
            _mnr.RegisterFunction("tolower", FuncToLower);
            _mnr.RegisterFunction("isdefined", FuncIsDefined);
            _mnr.RegisterFunction("ifvariable", FuncIfVariable);
            _mnr.RegisterFunction("ifdefined", FuncIfDefined);
            _mnr.RegisterFunction("len", FuncLen);
            _mnr.RegisterFunction("join", FuncJoin);
            _mnr.RegisterFunction("split", FuncSplit);
            _mnr.RegisterFunction("isnull", FuncIsNull);
            _mnr.RegisterFunction("not", FuncNot);
            _mnr.RegisterFunction("iif", FuncIif);
            _mnr.RegisterFunction("format", FuncFormat);
            _mnr.RegisterFunction("trim", FuncTrim);
            _mnr.RegisterFunction("filter", FuncFilter);
            _mnr.RegisterFunction("replace", FuncReplace);
            _mnr.RegisterFunction("sweep", FuncSweep);
            _mnr.RegisterFunction("replacewith", FuncReplaceWith);
            _mnr.RegisterFunction("round", FuncRound);
            _mnr.RegisterFunction("typeof", FuncTypeOf);
            _mnr.RegisterFunction("cint", FuncCInt);
            _mnr.RegisterFunction("cdouble", FuncCDouble);
            _mnr.RegisterFunction("cdate", FuncCDate);
            _mnr.RegisterFunction("now", FuncNow);
            _mnr.RegisterFunction("typeref", FuncTypeRef);
            _mnr.RegisterFunction("templates", FuncTemplates);
            _mnr.RegisterFunction("todict", FuncToDict);
#if CSHARP30
            _mnr.RegisterFunction("query", FuncQuery);
#endif
            _mnr.RegisterFunction("readfile", FuncReadFile);
            _mnr.RegisterFunction("writefile", FuncWriteFile);
            _mnr.RegisterFunction("write", FuncWrite);
            _mnr.RegisterFunction("writeline", FuncWriteLine);
        }
示例#5
0
        public static void Register(TmplManager mn, Templates _tpl)
        {
            _mnr       = mn;
            _Templates = _tpl;

            _mnr.RegisterFunction("contains"      , FuncContains);
            _mnr.RegisterFunction("isnullorempty" , FuncIsNullOrEmpty);
            _mnr.RegisterFunction("isnotempty"    , FuncIsNotEmpty);
            _mnr.RegisterFunction("isnumber"      , FuncIsNumber);
            _mnr.RegisterFunction("toupper"       , FuncToUpper);
            _mnr.RegisterFunction("tolower"       , FuncToLower);
            _mnr.RegisterFunction("isdefined"     , FuncIsDefined);
            _mnr.RegisterFunction("ifvariable"    , FuncIfVariable);
            _mnr.RegisterFunction("ifdefined"     , FuncIfDefined);
            _mnr.RegisterFunction("len"           , FuncLen);
            _mnr.RegisterFunction("join"          , FuncJoin);
            _mnr.RegisterFunction("split"         , FuncSplit);
            _mnr.RegisterFunction("isnull"        , FuncIsNull);
            _mnr.RegisterFunction("not"           , FuncNot);
            _mnr.RegisterFunction("iif"           , FuncIif);
            _mnr.RegisterFunction("format"        , FuncFormat);
            _mnr.RegisterFunction("trim"          , FuncTrim);
            _mnr.RegisterFunction("filter"        , FuncFilter);
            _mnr.RegisterFunction("replace"       , FuncReplace);
            _mnr.RegisterFunction("sweep"         , FuncSweep);
            _mnr.RegisterFunction("replacewith"   , FuncReplaceWith);
            _mnr.RegisterFunction("round"         , FuncRound);
            _mnr.RegisterFunction("typeof"        , FuncTypeOf);
            _mnr.RegisterFunction("cint"          , FuncCInt);
            _mnr.RegisterFunction("cdouble"       , FuncCDouble);
            _mnr.RegisterFunction("cdate"         , FuncCDate);
            _mnr.RegisterFunction("now"           , FuncNow);
            _mnr.RegisterFunction("typeref"       , FuncTypeRef);
            _mnr.RegisterFunction("templates"     , FuncTemplates);
            _mnr.RegisterFunction("todict"        , FuncToDict);
            #if CSHARP30
            _mnr.RegisterFunction("query"         , FuncQuery);
            #endif
            _mnr.RegisterFunction("readfile"      , FuncReadFile);
            _mnr.RegisterFunction("writefile"     , FuncWriteFile);
            _mnr.RegisterFunction("write"         , FuncWrite);
            _mnr.RegisterFunction("writeline"     , FuncWriteLine);
        }