示例#1
0
        public static IQueryOrderBy Field(Type type, string field, QueryOrderType orderType)
        {
            var expressionOrderBy =
                (AbstractExpressionOrderBy)_factory.CreateOrderBy(QueryOrderByExpressionType.Expression);

            expressionOrderBy.Expr      = OrderByExpr.Build().Field(type, field);
            expressionOrderBy.OrderType = orderType;
            return(expressionOrderBy);
        }
示例#2
0
        public async Task <string> QueryOrderListAsync(QueryOrderType Type)
        {
            string[] channel_list = { "9", "30", "31", "35", "38", "52", "97", "122", "135", "322", " - 1" };
            var      r            = await Session.Request(string.Format("proxy/api/api/aristotle/order_list?pdduid={0}", token.uid)).PostStringAsync(

                JsonConvert.SerializeObject(new
            {
                timeout          = 1300,
                type             = Type.ToString(),
                page             = 1,
                origin_host_name = "mobile.yangkeduo.com",
                pay_channel_list = channel_list,
                size             = 10
            })

                );;

            return(await r.Content.ReadAsStringAsync());
        }
示例#3
0
        public static IQueryOrderBy Field <T>(Expression <Func <T, object> > prop, QueryOrderType orderType)
        {
            var fieldName = ReflectionUtils.GetPropertyNameFromExpression(prop);

            return(Field(typeof(T), fieldName, orderType));
        }
示例#4
0
 private void BuildMemberComparison(TypeNode host, StatementList stats, Expression v1, Expression v2, QueryOrderType ot, Expression retval) {
   Debug.Assert(stats != null && v1 != null && v2 != null && v1.Type != null && v2.Type != null, "BuildComparison");
   Debug.Assert(v1.Type == v2.Type, "Comparison types must match");
   NodeType gt = (ot == QueryOrderType.Ascending) ? NodeType.Gt : NodeType.Lt;
   NodeType lt = (ot == QueryOrderType.Ascending) ? NodeType.Lt : NodeType.Gt;
   // quick check identity equality
   Cardinality card = this.typeSystem.GetCardinality(v1, this.TypeViewer);
   switch (card) {
     case Cardinality.One:
       if (v1.Type.Template == SystemTypes.GenericNonNull) {
         v1 = this.GetValueExpression(v1);
         v2 = this.GetValueExpression(v2);
       }
       break;
     case Cardinality.None:
     case Cardinality.ZeroOrOne:
       Expression v1IsNull = this.GetIsNullExpression(v1);
       Expression v2IsNull = this.GetIsNullExpression(v2);
       Block brV1IsNull = new Block();
       Block brV2IsNull = new Block();
       Block brBothAreNull = new Block();
       Block brNeitherAreNull = new Block();
       stats.Add(new Branch(v1IsNull, brV1IsNull));
       stats.Add(new Branch(v2IsNull, brV2IsNull));
       stats.Add(new Branch(null, brNeitherAreNull));
       stats.Add(brV1IsNull);
       stats.Add(new Branch(v2IsNull, brBothAreNull));
       stats.Add(new Return(Literal.Int32MinusOne));
       stats.Add(brV2IsNull);
       stats.Add(new Return(Literal.Int32One));
       stats.Add(brBothAreNull);
       stats.Add(new Return(Literal.Int32Zero));
       stats.Add(brNeitherAreNull);
       v1 = this.GetNonNullExpression(v1);
       v2 = this.GetNonNullExpression(v2);
       break;
     case Cardinality.OneOrMore:
     case Cardinality.ZeroOrMore:
       // todo: deep comparison of streams
       return;
   }
   if (this.GetTypeView(v1.Type).IsAssignableTo(SystemTypes.IComparable)) {
     Method mth = this.GetTypeView(v1.Type).GetMethod(Identifier.For("CompareTo"), SystemTypes.Object);
     MethodCall mc = new MethodCall(new MemberBinding(v1, mth), new ExpressionList(this.typeSystem.ImplicitCoercion(v2, SystemTypes.Object, this.TypeViewer)));
     mc.Type = mth.ReturnType;
     stats.Add(new AssignmentStatement(retval, this.VisitMethodCall(mc)));
   }else{
     Method m = this.BuildComparisonMethod(host, v1.Type);
     MethodCall mc = new MethodCall(new MemberBinding(null, m), new ExpressionList(v1, v2));
     mc.Type = m.ReturnType;
     stats.Add(new AssignmentStatement(retval, mc));
   }
 }
示例#5
0
 private Method BuildComparisonMethod(TypeNode host, TypeNode type, MemberList members, QueryOrderType[] orders, int n) {
   Method method = new Method(host, null, idCompareType, new ParameterList(2), SystemTypes.Int32, new Block(new StatementList()));
   method.Flags = MethodFlags.Private|MethodFlags.Static;
   method.Parameters.Add(new Parameter(null, ParameterFlags.In, Identifier.For("p1"), type, null, null));
   method.Parameters.Add(new Parameter(null, ParameterFlags.In, Identifier.For("p2"), type, null, null));
   host.Members.Add(method);
   StatementList stats = method.Body.Statements;
   Expression loc1 = method.Parameters[0];
   Expression loc2 = method.Parameters[1];
   if (!type.IsValueType) {
     Block brNotEqual = new Block();
     stats.Add(new Branch(new BinaryExpression(loc1, loc2, NodeType.Ne), brNotEqual));
     stats.Add(new Return(Literal.Int32Zero));
     stats.Add(brNotEqual);
   }
   // generate comparison logic for each member in the list
   Local retval = new Local(SystemTypes.Int32);
   for(int i = 0; i < n; i++) {
     Member m = members[i];
     TypeNode mtype = this.typeSystem.GetMemberType(m);
     QueryOrderType ot = (orders != null) ? orders[i] : QueryOrderType.Ascending;
     MemberBinding m1 = new MemberBinding(loc1, m); m1.Type = mtype;
     MemberBinding m2 = new MemberBinding(loc2, m); m2.Type = mtype;
     this.BuildMemberComparison(host, stats, m1, m2, ot, retval);
     Block next = new Block();
     stats.Add(new Branch(new BinaryExpression(retval, Literal.Int32Zero, NodeType.Eq), next));
     if (ot == QueryOrderType.Descending) {
       UnaryExpression ue = new UnaryExpression(retval, NodeType.Neg);
       ue.Type = SystemTypes.Int32;
       stats.Add(new Return(ue));
     }
     else {
       stats.Add(new Return(retval));
     }
     stats.Add(next);
   }
   stats.Add(new Return(Literal.Int32Zero));
   return method;
 }
示例#6
0
    private TypeNode BuildComparer(TypeNode type, MemberList members, QueryOrderType[] orders, int n) {
      Debug.Assert(members != null && n > 0 && n <= members.Count);
      Identifier name = Identifier.For("comparer"+type.UniqueKey);
      Class cc = new Class();
      cc.DeclaringModule = this.currentModule;
      cc.DeclaringType = this.currentType;
      cc.Flags = TypeFlags.NestedPublic;
      cc.Namespace = Identifier.Empty;
      cc.Name = name;
      cc.BaseClass = SystemTypes.Object;
      cc.Interfaces = new InterfaceList(2);
      cc.Interfaces.Add(SystemTypes.IComparer);
      cc.Interfaces.Add(SystemTypes.IHashCodeProvider);

      // constructor
      Method init = new InstanceInitializer(cc, null, new ParameterList(), new Block(new StatementList(1)));
      init.Flags |= MethodFlags.Public;
      cc.Members.Add(init);
      Method mthBaseCons = SystemTypes.Object.GetMethod(StandardIds.Ctor);
      MethodCall mcBase = new MethodCall(new MemberBinding(init.ThisParameter, mthBaseCons), null);
      mcBase.Type = SystemTypes.Void;
      init.Body.Statements.Add(new ExpressionStatement(mcBase));
      
      // CompareTo
      Method mcomp = new Method(cc, null, Identifier.For("Compare"), new ParameterList(2), SystemTypes.Int32, new Block(new StatementList()));
      mcomp.Flags = MethodFlags.Public|MethodFlags.Virtual|MethodFlags.Final;
      mcomp.CallingConvention = CallingConventionFlags.HasThis;
      mcomp.Parameters.Add(new Parameter(null, ParameterFlags.In, Identifier.For("p1"), SystemTypes.Object, null, null));
      mcomp.Parameters.Add(new Parameter(null, ParameterFlags.In, Identifier.For("p2"), SystemTypes.Object, null, null));
      cc.Members.Add(mcomp);

      // GetHashCode(obj)
      Method mhash = new Method(cc, null, Identifier.For("GetHashCode"), new ParameterList(1), SystemTypes.Int32, new Block(new StatementList()));
      mhash.Flags = MethodFlags.Public|MethodFlags.Virtual|MethodFlags.Final;
      mhash.CallingConvention = CallingConventionFlags.HasThis;
      mhash.Parameters.Add(new Parameter(null, ParameterFlags.In, Identifier.For("p1"), SystemTypes.Object, null, null));
      cc.Members.Add(mhash);

      // call type specific comparison
      Method mcomptype = this.BuildComparisonMethod(cc, type, members, orders, n);
      MethodCall mccomptype = new MethodCall(
        new MemberBinding(null, mcomptype), 
        new ExpressionList(this.Unbox(mcomp.Parameters[0], type), this.Unbox(mcomp.Parameters[1], type))
        );
      mccomptype.Type = mcomptype.ReturnType;
      Block brNotEqual = new Block();
      mcomp.Body.Statements.Add(new Branch(new BinaryExpression(mcomp.Parameters[0], mcomp.Parameters[1], NodeType.Ne), brNotEqual));
      mcomp.Body.Statements.Add(new Return(Literal.Int32Zero));
      mcomp.Body.Statements.Add(brNotEqual);
      mcomp.Body.Statements.Add(new Return(mccomptype));

      this.BuildGetHashCodeBody(mhash, type, members, n);
      return cc;
    }
示例#7
0
 private TypeNode BuildComparer(TypeNode type, MemberList members, QueryOrderType[] orders) {
   return this.BuildComparer(type, members, orders, members.Count);
 }