Ejemplo n.º 1
0
        public static IEnumerable <T> GetListOrder <T>(IEnumerable <T> inList, string orderFiled, string orderType, ref ProInterface.ErrorInfo error)
        {
            if (!string.IsNullOrEmpty(orderFiled))
            {
                try
                {
                    var dateType = Fun.GetClassProperType <T>(orderFiled).ToLower();
                    switch (dateType)
                    {
                    case "decimal":
                        Func <T, decimal> whereFuncDecimal = StringToLambda.LambdaParser.Compile <Func <T, decimal> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFuncDecimal);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFuncDecimal);
                        }
                        break;

                    case "int":
                        Func <T, int> whereFuncInt = StringToLambda.LambdaParser.Compile <Func <T, int> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFuncInt);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFuncInt);
                        }
                        break;

                    case "int32":
                        Func <T, Int32> whereFuncInt32 = StringToLambda.LambdaParser.Compile <Func <T, Int32> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFuncInt32);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFuncInt32);
                        }
                        break;

                    case "datetime":
                        Func <T, DateTime> whereFuncDatetime = StringToLambda.LambdaParser.Compile <Func <T, DateTime> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFuncDatetime);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFuncDatetime);
                        }
                        break;

                    default:
                        Func <T, string> whereFunc = StringToLambda.LambdaParser.Compile <Func <T, string> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFunc);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFunc);
                        }
                        break;
                    }
                    return(inList);
                }
                catch
                {
                    error.IsError = true;
                    error.Message = "条件表态式[" + orderFiled + "]有误";
                }
            }
            return(inList);
        }