Ader Template Engine exstact
2012-12-05 10:39 露珠的微笑 阅读(982) 评论(0) 收藏 举报from http://www.codeproject.com/Articles/8141/Ader-Template-Engine,
中文参考boke:http://www.cnblogs.com/caicaihui/archive/2008/07/07/1237756.html
Ader TemplateEngine is a .NET class library (written in C#) for generating text output from source template and input parameters.
Functions :
equals(obj1, obj2)- invokesequalsmethod onobj1withobj2as parameter. Returns boolean value.- cint(value) - return an int of value ,same as :Convert.toInt32() in C#
- cdouble(value) -return an double data
- cdata(value)
- createtypereference(type) - reference a static type
exp: #createtypereference("System.Math").Round(3.39789)#
#createtypereference("System.Math").PI#
or
< ad:set name="MyMath" value="#createtypereference("System.Math")#" />
#MyMath.Round(3.3)#
#MyMath.PI#
notequals(obj1, obj2)- Returns!equals(obj1, obj2). Is equivalent to calling:not(equals(obj1, obj2)).iseven(num)- tests whether number is an even number.isodd(num)- tests whether number is an odd number.isempty(string)- tests whether string has 0 characters. Same asequals(string.Length, 0).isnotempty(string)- tests whether string has at least 1 character.isnumber(num)- tests whethernumis of numeric type.toupper(string)- convertsstringto upper case.tolower(string)- convertsstringto lower case.isdefined(varname)- tests whether variable namedvarnameis defined.ifdefined(varname, value)- returns value ifvarnameis defined. Especially useful:#ifdefined("name", name)#- will output value ofnameif it's defined, otherwise will output nothing.len(string)- returns length ofstring.tolist(collection, property, delim)- will convertcollectionto string withdelimas separator. If you passproperty, the value of thepropertywill be evaluated on each element of the collection. If you omitproperty, then the object itself will be used.- typeof(object) -returns type of object,exp:typeof("abcd234") return"string" , typeof(3) return int
-
isnull(obj)- tests whetherobjisnull not(boolvalue)- returns not (!) of boolean value.iif(booleanExpression, iftruevalue, iffalsevalue)- same asbooleanExpression ? iftruevalue : iffalsevaluein C#.format(object, formatstring)- will callToString(formatstring)onobject.objecthas to implementIFormattableinterface, otherwiseToString()will be called.-
trim(string)- will trimstringobject -
filter(collection, booleanproperty)- will return new List fromcollectionfor those objects whose boolean property property evaluates totrue. -
gt(obj1, obj2)- will returntrueifobj1>obj2. (obj1andobj2must implementIComparable. All numeric types do). -
lt(obj1, obj2)- will returntrueifobj1<obj2. (obj1andobj2must implementIComparable. All numeric types do). -
compare(obj1, obj2)- will return -1 ifobj1<obj2, 0 ifobj1=obj2, and 1 ifobj1>obj2. (obj1andobj2must implementIComparable. All numeric types do). comparenocase(string1, string2)- will do case insensitive comparison ofstring1andstring2and returntrueif they are equal.-
or(bool1, bool2)- will returntrueif eitherbool1orbool2aretrue. and(bool1, bool2) -will returntrueif bothbool1andbool2aretrue.stripnewlines(string)- will return all\r\ninstances and replace them with space.
Built In Tags:
-
IF
<ad:if test="#equals(cust.country, "US"))#"> You are US customer. <ad:else> You are from: #cust.country# country. </ad:if>
-
FOREACH
You can loop through collection of elements (any object that implements IEnumerable interface) using FOREACH tag.
<ad:foreach collection="#collection#" var="cust" index="i"> #i#: #cust.lastname#, #cust.firstname# </ad:foreach>
基于.NET的免费开源的另模板引擎---VTemplate参考Kingthy's blog http://www.cnblogs.com/kingthy/archive/2009/08/17/net-vtemplate.html
浙公网安备 33010602011771号