server/aspnetapp/Helper/PageExtension.cs

(开头部分) 8KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace aspnetapp.Helper
{
    public static class QueryableExtender
    {
        public static IQueryable<T> _Page<T>(this IQueryable<T> @this)
        {
            return @this;
        }
        public static IQueryable<T> _Page<T>(this IQueryable<T> @this, int page = 1, int pagesize = 10)
        {
            return @this.Skip(pagesize * (page - 1)).Take(pagesize);
        }
        public static int _PageCount<T>(this IQueryable<T> @this)
        {
            return 0;
        }
        public static int _PageCount<T>(this IQueryable<T> @this, int page = 1, int pagesize = 10)
        {
            int count = @this.Count();
            return count % pagesize == 0 ? count / pagesize : count / pagesize + 1;
        }
    }
    public static class StringExtender
    {
        public static string _CreateGuid(this string @this)
        {
            return Guid.NewGuid().ToString().Replace("-", "");
        }
    }
    public static class DynamicLinqExpressions
    {

        public static Expression<Func<T, bool>> _True<T>() { return f => true; }
        public static Expression<Func<T, bool>> _False<T>() { return f => false; }

        public static Expression<Func<T, bool>> _Or<T>(this Expression<Func<T, bool>> expr1,
                                                            Expression<Func<T, bool>> expr2)
        {
            InvocationExpression invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
            return Expression.Lambda<Func<T, bool>>
                  (Expression.Or(expr1.Body, invokedExpr), expr1.Parameters);
        }

        public static Expression<Func<T, bool>> _And<T>(this Expression<Func<T, bool>> expr1,
                                                             Expression<Func<T, bool>> expr2)
        {
            InvocationExpression invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
            return Expression.Lambda<Func<T, bool>>
                  (Expression.And(expr1.Body, invokedExpr), expr1.Parameters);
        }
        public static TSource _UpdateModel<TSource>(this TSource source, TSource target, Expression<Func<TSource, object>> predicate)
        {
            if (source != null)
            {
后面还有 145 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。