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 VoltException("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 = VoltEngine.ProcessProperty(ienum.Current, property); if (val is bool && (bool)val) { newList.Add(ienum.Current); } } return(newList); }
public string Evaluate(string expression) { VoltEngine Volt = VoltEngine.Parser("${" + expression + "}"); StringWriter writer = new StringWriter(); Volt.Process(writer); return(writer.ToString()); }
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 VoltException("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(VoltEngine.ProcessProperty(ienum.Current, property)); } index++; } return(sb.ToString()); }
public static void Register(VoltEngine 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("listcontains", FuncListContains); _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("regions", FuncRegions); _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); }
public static VoltEngine Parser(string tmpl) { return(VoltEngine.Parser("", tmpl)); }