Example #1
0
            /// <summary>
            /// Emit lambda function that returns values used for sorting and
            /// call to OrderedSequence.OrderBy method (with current LINQ context as
            /// first and generated lambda as a second parameter)
            /// </summary>
            public override PhpTypeCode Emit(LinqBuilder codeGenerator)
            {
                ILEmitter il = codeGenerator.IL;

                // NEW Func[object,object](<linq context>, <&lambda>);
                codeGenerator.EmitLoadLinqContext();
                il.Emit(OpCodes.Ldftn, codeGenerator.EmitLambda(string.Format("<Comparer_{0}>",
                                                                              codeGenerator.GetNextComparerNum()), valueVar, expression, PhpTypeCode.Object));
                il.Emit(OpCodes.Newobj, LinqExterns.Func2_object_object_ctor);

                // LOAD Select[object,object](<source>, <delegate>);
                if (isThenBy)
                {
                    il.Emit(OpCodes.Call, ordering == Ordering.Descending ? LinqExterns.ThenByDescending : LinqExterns.ThenBy);
                }
                else
                {
                    il.Emit(OpCodes.Call, ordering == Ordering.Descending ? LinqExterns.OrderByDescending : LinqExterns.OrderBy);
                }

                return(base.Emit(codeGenerator));
            }