Unquote (Compiler Magic Function)

From The Oxygene Language Wiki

Jump to:navigation, search

Unquote is new compiler function introduced in the May 2009 Release (3.0.19), that can be used to insert values as-is in a Cirrus or LINQ expression, instead of converting them to an expression tree class. Unquote has two overloads, the first one takes a generic parameter, which will be the result type of the expression at runtime, the second one doesn't, and will be treated as having no result, which is useful to insert dynamically generated statements with Cirrus.

method FetchCustomer(aCondition: Expression): IQueryable<Customer>;
begin
  exit from x in fDatabase.Customers where unquote<Boolean>(aCondition);
end;

Cirrus:

var lAssignment := new AssignmentStatement(lField, lExpr);
  var lSelf := iif(aProperty.Static, new TypeOfValue(aProperty.Owner.GetSelfType), 
      new SelfValue());
  aRead.SetBody(Services, method begin
    if not unquote<Boolean>(lFieldSet) then begin
      locking unquote<object>(lSelf) do begin
        if not unquote<Boolean>(lFieldSet) then begin
          unquote(lAssignment);
          unquote<Boolean>(lFieldSet) := true;
        end;
      end;
    end;
    exit unquote(lField);
  end);
Navigation
Areas
More
Toolbox