//
// 本例展示了各种新的表达式格式
//
using System.Collections.Generic
Function Start() as void
VAR oNone := Person{"No", "Parent"}
FOREACH VAR oValue in GetList()
if oValue IS STRING // Value IS Type
? (String) oValue
ELSEIF oValue IS INT
? (Int) oValue
ELSEIF oValue IS DateTime
? (DateTime) oValue
ELSEIF oValue IS Person
LOCAL oPerson as Person
oPerson := (Person) oValue
? oPerson:FirstName, oPerson:LastName
// Value DEFAULT Value2 。当 Value IS NULL 时,将使用 Value2
oPerson := oPerson:Parent DEFAULT oNone
? "Parent: ", oPerson:FirstName, oPerson:LastName
ENDIF
NEXT
LOCAL oEmptyPerson as Person
LOCAL sName as STRING
oEmptyPerson := GetAPerson()
sName := oEmptyPerson?:FirstName // 有条件访问: 即使 Person 为 NULL_OBJECT,也不会崩溃
? sName DEFAULT "None"
Console.ReadLine()
RETURN
FUNCTION GetList() AS List<OBJECT>
VAR aList := List<OBJECT>{}
aList:Add(DateTime.Now)
aList:Add("abcdefg")
aList:Add(123456)
VAR oPerson := Person{"John", "Doe"}
aList:Add(oPerson)
VAR oChild := Person{"Jane", "Doe"}
oChild:Parent := oPerson
aList:Add(oChild)
RETURN aList
CLASS Person
EXPORT FirstName AS STRING
EXPORT LastName as STRING
EXPORT Parent as Person
CONSTRUCTOR(First as STRING, Last as STRING)
FirstName := First
LastName := Last
END CLASS
FUNCTION GetAPerson() as Person
RETURN NULL_OBJECT