cs-Panination

ylbtech-Unitity: cs-Panination

Pager.cs 

IPagingOption.cs IPagedList.cs

PagingOption.cs PagedList.cs

PagingExtensions.cs

1.A,效果图返回顶部
1.B,源代码返回顶部
1.B.1,Pager.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Routing;
using Healthcare.Framework.Web.URL;namespace Healthcare.Framework.Web.Mvc.Pagination
{public class Pager{ private ViewContext viewContext;private int currentPage;private int pageCount;private RouteValueDictionary pageLinkValueDictionary;private readonly int pageSize;private readonly int totalItemCount;private readonly RouteValueDictionary linkWithoutPageValuesDictionary;private readonly AjaxOptions ajaxOptions;private readonly string sortBy;private readonly bool? sortDescending;public Pager(ViewContext viewContext, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary, AjaxOptions ajaxOptions){this.viewContext = viewContext;this.pageSize = pageSize;this.currentPage = currentPage;this.totalItemCount = totalItemCount;this.linkWithoutPageValuesDictionary = valuesDictionary;this.ajaxOptions = ajaxOptions;this.ensureCollectionPageLinkValue();}public Pager(ViewContext viewContext, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, RouteValueDictionary valuesDictionary, AjaxOptions ajaxOptions){this.viewContext = viewContext;this.pageSize = pageSize;this.currentPage = currentPage;this.totalItemCount = totalItemCount;this.sortBy = sortBy;this.sortDescending = sortDescending;this.linkWithoutPageValuesDictionary = valuesDictionary;this.ajaxOptions = ajaxOptions;this.ensureCollectionPageLinkValue();}public HtmlString RenderHtml(){pageCount = (int)Math.Ceiling(totalItemCount / (double)pageSize);if (pageCount == 0) pageCount = 1;const int nrOfPagesToDisplay = 4;if (pageCount < currentPage)currentPage = pageCount;var sb = new StringBuilder();// Previoussb.Append("<ul class=\"pagination pull-right\">");sb.Append(currentPage > 1 ? GeneratePageLink("«", 1, "first") : "<li class=\"first disabled\"><a>«</a></li>");sb.Append(currentPage > 1 ? GeneratePageLink("", currentPage - 1, "previous") : "<li class=\"previous disabled\"><a>‹</a></li>");var start = 1;var end = pageCount;if (pageCount > nrOfPagesToDisplay){var middle = (int)Math.Ceiling(nrOfPagesToDisplay / 2d) - 1;var below = (currentPage - middle);var above = (currentPage + middle);if (below < 4){above = nrOfPagesToDisplay;below = 1;}else if (above > (pageCount - 4)){above = pageCount;below = (pageCount - nrOfPagesToDisplay);}start = below;end = above;}if (start > 3){sb.Append(GeneratePageLink("1", 1));sb.Append(GeneratePageLink("2", 2));sb.Append("<li class=\"disabled\"><a>...</a></li>");}for (var i = start; i <= end; i++){if (i == currentPage || (currentPage <= 0 && i == 0)){sb.AppendFormat("<li class=\"active\"><a>{0}</a></li>", i);}else{sb.Append(GeneratePageLink(i.ToString(), i));}}//if (end < (pageCount - 5))//{//    sb.Append("<li class=\"disabled\"><a>...</a></li>");//    sb.Append(GeneratePageLink((pageCount - 3).ToString(), pageCount - 3));//    sb.Append(GeneratePageLink((pageCount - 2).ToString(), pageCount - 2));//    sb.Append(GeneratePageLink((pageCount - 1).ToString(), pageCount - 1));//    sb.Append(GeneratePageLink(pageCount.ToString(), pageCount));//}if (end  < pageCount)//后面还有其它页码
            {int tempmin = pageCount - 3;sb.Append("<li class=\"disabled\"><a>...</a></li>");for (int k = tempmin; k <= pageCount; k++){sb.Append(GeneratePageLink(k.ToString(), k));}//sb.Append(GeneratePageLink(pageCount.ToString(), pageCount));
            }// Nextsb.Append(currentPage < pageCount ? GeneratePageLink("", (currentPage + 1), "next") : "<li class=\"next disabled\"><a>›</a></li>");sb.Append(currentPage < pageCount ? GeneratePageLink("»", pageCount, "last") : "<li class=\"last disabled\"><a>»</a></li>");sb.Append("</ul>");return new HtmlString(sb.ToString());}private string GeneratePageLink(string linkText, int pageNumber, string classText = ""){if (pageLinkValueDictionary.ContainsKey("Page")){pageLinkValueDictionary.Remove("Page");}pageLinkValueDictionary.Add("Page", pageNumber);// 'Render' virtual path.var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(viewContext.RequestContext, pageLinkValueDictionary);if (virtualPathForArea == null)return null;var stringBuilder = new StringBuilder("<li class=\"" + classText + "\"><a");if (ajaxOptions != null)foreach (var ajaxOption in ajaxOptions.ToUnobtrusiveHtmlAttributes())stringBuilder.AppendFormat(" {0}=\"{1}\"", ajaxOption.Key, ajaxOption.Value);stringBuilder.AppendFormat(" href=\"{0}\">{1}</a></li>", virtualPathForArea.VirtualPath, linkText);return stringBuilder.ToString();}public HtmlString RenderGotoBaseUrl(){if (pageLinkValueDictionary.ContainsKey("Page")){pageLinkValueDictionary.Remove("Page");}var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(viewContext.RequestContext, pageLinkValueDictionary);return new HtmlString(virtualPathForArea.VirtualPath);}public HtmlString RenderSwitchPageSizeBaseUrl(){if (pageLinkValueDictionary.ContainsKey("PageSize")){pageLinkValueDictionary.Remove("PageSize");}if (pageLinkValueDictionary.ContainsKey("Page")){pageLinkValueDictionary.Remove("Page");}var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(viewContext.RequestContext, pageLinkValueDictionary);return new HtmlString(virtualPathForArea.VirtualPath);}private void ensureCollectionPageLinkValue(){pageLinkValueDictionary = new RouteValueDictionary(linkWithoutPageValuesDictionary) { { "SortBy", sortBy }, { "SortDescending", sortDescending } };//{ { "Page", pageNumber }, { "PageSize", pageSize }, };
Dictionary<string, string> dict = new Dictionary<string, string>();QueryStringHelper.ExtractQueryStringValuesFromUri(viewContext.HttpContext.Request.Url, ref dict);dict.Keys.ToList().ForEach(key =>{if (!pageLinkValueDictionary.ContainsKey(key)){pageLinkValueDictionary.Add(key, dict[key]);}});// To be sure we get the right route, ensure the controller and action are specified.var routeDataValues = viewContext.RequestContext.RouteData.Values;routeDataValues.Keys.ToList().ForEach(key =>{if (!pageLinkValueDictionary.ContainsKey(key)){pageLinkValueDictionary.Add(key, routeDataValues[key]);}});}}
}
View Code

1.B.2,IPagingOption.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;namespace Healthcare.Framework.Web.Mvc.Pagination
{public interface IPagingOption{ int Page { get; set; }int PageSize { get; set; }int? TotalCount { get; set; }string SortBy { get; set; }bool? SortDescending { get; set; }string OrderByExpression { get; }RouteValueDictionary RouteValues { get; set; }}
}
View Code

1.B.3,IPagedList.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;namespace Healthcare.Framework.Web.Mvc.Pagination
{public interface IPagedList<T> : IList<T>{ int PageCount { get; }int TotalItemCount { get; }int PageIndex { get; }int PageNumber { get; }int PageSize { get; }bool HasPreviousPage { get; }bool HasNextPage { get; }bool IsFirstPage { get; }bool IsLastPage { get; }string SortBy { get; }bool? SortDescending { get; }RouteValueDictionary RouteValues { get; }}
}
View Code

1.B.4,PagingOption.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;namespace Healthcare.Framework.Web.Mvc.Pagination
{public class PagingOption : IPagingOption{public int Page { get; set; }public int PageSize { get; set; }public int? TotalCount { get; set; }public Int32? IsPagination { get; set; }public string ActionName { get; set; }public string SortBy { get; set; }public bool? SortDescending { get; set; }public bool ShowSummary { get; set; }public bool ShowGoto { get; set; }public bool ShowPageSize { get; set; }public PagingOption(){TotalCount = 0;PageSize = 10;Page = 1;}public RouteValueDictionary RouteValues { get; set; }public string OrderByExpression{get{return this.SortDescending.HasValue && this.SortDescending.Value ? this.SortBy + " desc" : this.SortBy + " asc";}}public int PageTotal{get{if (TotalCount == null){return (int)Math.Ceiling(0 / (double)PageSize);}return (int)Math.Ceiling(TotalCount.Value / (double)PageSize);}}}
}
View Code

1.B.5,PagedList.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;namespace Healthcare.Framework.Web.Mvc.Pagination
{public class PagedList<T> : List<T>, IPagedList<T>{ public PagedList(IEnumerable<T> source, IPagingOption option): this(source.AsQueryable(), option){}public PagedList(IQueryable<T> source, IPagingOption option){if (option == null)throw new ArgumentOutOfRangeException("PagingOption", "Value can not be null.");if (option.Page < 0)throw new ArgumentOutOfRangeException("index", "Value must be greater than 0.");if (option.PageSize < 1)throw new ArgumentOutOfRangeException("pageSize", "Value must be greater than 1.");if (source == null)source = new List<T>().AsQueryable();var realTotalCount = source.Count();PageSize = option.PageSize;PageIndex = option.Page;RouteValues = option.RouteValues;TotalItemCount = option.TotalCount.HasValue ? option.TotalCount.Value : realTotalCount;PageCount = TotalItemCount > 0 ? (int)Math.Ceiling(TotalItemCount / (double)PageSize) : 0;SortBy = option.SortBy;SortDescending = option.SortDescending;if (!string.IsNullOrEmpty(option.SortBy))source = source.OrderBy(option.OrderByExpression);HasPreviousPage = (PageIndex > 0);HasNextPage = (PageIndex < (PageCount - 1));IsFirstPage = (PageIndex <= 0);IsLastPage = (PageIndex >= (PageCount - 1));if (TotalItemCount <= 0)return;var realTotalPages = (int)Math.Ceiling(realTotalCount / (double)PageSize);if (realTotalCount < TotalItemCount && realTotalPages <= PageIndex)AddRange(source.Skip((realTotalPages - 1) * PageSize).Take(PageSize));elseAddRange(source.Skip(PageIndex * PageSize).Take(PageSize));}#region IPagedList Memberspublic int PageCount { get; private set; }public int TotalItemCount { get; private set; }public int PageIndex { get; private set; }public int PageNumber { get { return PageIndex + 1; } }public int PageSize { get; private set; }public bool HasPreviousPage { get; private set; }public bool HasNextPage { get; private set; }public bool IsFirstPage { get; private set; }public bool IsLastPage { get; private set; }public string SortBy { get; private set; }public bool? SortDescending { get; private set; }public RouteValueDictionary RouteValues { get; set; }#endregion}
}
View Code

1.B.6,PagingExtensions.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Mvc.Html;
using System.Web.Routing;namespace Healthcare.Framework.Web.Mvc.Pagination
{public static class PagingExtensions{ #region AjaxHelper extensionspublic static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, AjaxOptions ajaxOptions){return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, null, null, ajaxOptions);}public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, string actionName, AjaxOptions ajaxOptions){return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, sortBy, sortDescending, actionName, null, ajaxOptions);}public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, string actionName, AjaxOptions ajaxOptions){return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, actionName, null, ajaxOptions);}public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, object values, AjaxOptions ajaxOptions){return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, null, new RouteValueDictionary(values), ajaxOptions);}public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, string actionName, object values, AjaxOptions ajaxOptions){return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, null, null, actionName, new RouteValueDictionary(values), ajaxOptions);}public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary, AjaxOptions ajaxOptions){return Pager(ajaxHelper, pageSize, currentPage, totalItemCount, null, valuesDictionary, ajaxOptions);}public static HtmlString Pager(this AjaxHelper ajaxHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, string actionName, RouteValueDictionary valuesDictionary, AjaxOptions ajaxOptions){if (valuesDictionary == null){valuesDictionary = new RouteValueDictionary();}if (actionName != null){if (valuesDictionary.ContainsKey("action")){throw new ArgumentException("The valuesDictionary already contains an action.", "actionName");}valuesDictionary.Add("action", actionName);}var pager = new Pager(ajaxHelper.ViewContext, pageSize, currentPage, totalItemCount, sortBy, sortDescending, valuesDictionary, ajaxOptions);return pager.RenderHtml();}#endregion#region HtmlHelper extensionspublic static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount){return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, null);}public static HtmlString PagerT(this HtmlHelper htmlHelper, PagingOption options){if (options == null)return new HtmlString("");if (options.RouteValues == null){options.RouteValues = new RouteValueDictionary();}var pager = new PagerT(htmlHelper.ViewContext, options.PageSize, options.Page, options.TotalCount.HasValue ? options.TotalCount.Value : 0, options.SortBy, options.SortDescending, options.RouteValues, null);return pager.RenderHtml();}public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending){return Pager(htmlHelper, pageSize, currentPage, totalItemCount, sortBy, sortDescending, null, null);}public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string actionName){return Pager(htmlHelper, pageSize, currentPage, totalItemCount, actionName, null);}public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, object values){return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, new RouteValueDictionary(values));}public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string actionName, object values){return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, null, actionName, new RouteValueDictionary(values));}public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary){return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, valuesDictionary);}public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, string actionName){return Pager(htmlHelper, pageSize, currentPage, totalItemCount, sortBy, sortDescending, actionName, null);}public static HtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string sortBy, bool? sortDescending, string actionName, RouteValueDictionary valuesDictionary){if (valuesDictionary == null){valuesDictionary = new RouteValueDictionary();}if (actionName != null){if (valuesDictionary.ContainsKey("action")){throw new ArgumentException("The valuesDictionary already contains an action.", "actionName");}valuesDictionary.Add("action", actionName);}var pager = new Pager(htmlHelper.ViewContext, pageSize, currentPage, totalItemCount, sortBy, sortDescending, valuesDictionary, null);return pager.RenderHtml();}public static HtmlString Pager(this HtmlHelper htmlHelper, PagingOption options){if (options == null)return new HtmlString("");if (options.RouteValues == null){options.RouteValues = new RouteValueDictionary();}var pager = new Pager(htmlHelper.ViewContext, options.PageSize, options.Page, options.TotalCount.HasValue ? options.TotalCount.Value : 0, options.SortBy, options.SortDescending, options.RouteValues, null);return pager.RenderHtml();}public static HtmlString PagerGotoURL(this HtmlHelper htmlHelper, PagingOption options){if (options == null)return new HtmlString("");if (options.RouteValues == null){options.RouteValues = new RouteValueDictionary();}var pager = new Pager(htmlHelper.ViewContext, options.PageSize, options.Page, options.TotalCount.HasValue ? options.TotalCount.Value : 0, options.SortBy, options.SortDescending, options.RouteValues, null);return pager.RenderGotoBaseUrl();}public static HtmlString PagerGotoURL(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, object values = null){PagingOption options = new PagingOption(){Page = 1,PageSize = pageSize,TotalCount = totalItemCount,RouteValues = new RouteValueDictionary(values)};return PagerGotoURL(htmlHelper, options);}public static HtmlString PagerSwitchPageSizeBaseUrl(this HtmlHelper htmlHelper, PagingOption options){if (options == null)return new HtmlString("");if (options.RouteValues == null){options.RouteValues = new RouteValueDictionary();}var pager = new Pager(htmlHelper.ViewContext, options.PageSize, options.Page, options.TotalCount.HasValue ? options.TotalCount.Value : 0, options.SortBy, options.SortDescending, options.RouteValues, null);return pager.RenderSwitchPageSizeBaseUrl();}public static HtmlString PagerSwitchPageSizeBaseUrl(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, object values = null){PagingOption options = new PagingOption(){Page = 1,PageSize = pageSize,TotalCount = totalItemCount,RouteValues = new RouteValueDictionary(values)};return PagerSwitchPageSizeBaseUrl(htmlHelper, options);}#endregion#region ActionLink extensionspublic static HtmlString ActionLink<T>(this AjaxHelper ajaxHelper, string name, string actionName, IPagedList<T> model, AjaxOptions ajaxOptions){var sortDescending = model.SortBy != null && model.SortBy.Equals(name) && model.SortDescending.HasValue && model.SortDescending.Value ? false : true;var routeValues = new RouteValueDictionary();routeValues.Add("SortBy", name);routeValues.Add("SortDescending", sortDescending);if (model.RouteValues != null){foreach (var r in model.RouteValues){routeValues.Add(r.Key, r.Value);}}IDictionary<string, object> htmlAttributes = new Dictionary<string, object>();var css = "";if (!string.IsNullOrEmpty(model.SortBy) && model.SortBy.Equals(name)){if (model.SortDescending.HasValue && model.SortDescending.Value)css = "sort-desc";elsecss = "sort-asc";}elsecss = "sort-off";htmlAttributes.Add("class", css);return ajaxHelper.ActionLink(name, actionName, routeValues, ajaxOptions, htmlAttributes);}public static HtmlString ActionLink<T>(this AjaxHelper ajaxHelper, string label, string name, string actionName, IPagedList<T> model, AjaxOptions ajaxOptions){var sortDescending = model.SortBy != null && model.SortBy.Equals(name) && model.SortDescending.HasValue && model.SortDescending.Value ? false : true;var routeValues = new RouteValueDictionary();routeValues.Add("SortBy", name);routeValues.Add("SortDescending", sortDescending);if (model.RouteValues != null){foreach (var r in model.RouteValues){routeValues.Add(r.Key, r.Value);}}IDictionary<string, object> htmlAttributes = new Dictionary<string, object>();var css = "";if (!string.IsNullOrEmpty(model.SortBy) && model.SortBy.Equals(name)){if (model.SortDescending.HasValue && model.SortDescending.Value)css = "sort-desc";elsecss = "sort-asc";}elsecss = "sort-off";htmlAttributes.Add("class", css);return ajaxHelper.ActionLink(label, actionName, routeValues, ajaxOptions, htmlAttributes);}public static HtmlString ActionLink<T>(this HtmlHelper htmlHelper, string name, string actionName, IPagedList<T> model){var sortDescending = model.SortBy != null && model.SortBy.Equals(name) && model.SortDescending.HasValue && model.SortDescending.Value ? false : true;var routeValues = new { SortBy = name, SortDescending = sortDescending };var css = "";if (!string.IsNullOrEmpty(model.SortBy) && model.SortBy.Equals(name)){if (model.SortDescending.HasValue && model.SortDescending.Value)css = "sort-desc";elsecss = "sort-asc";}elsecss = "sort-off";var htmlAttributes = new { @class = css };return htmlHelper.ActionLink(name, actionName, routeValues, htmlAttributes);}#endregion#region IQueryable<T> extensionspublic static IPagedList<T> ToPagedList<T>(this IQueryable<T> source, IPagingOption option){return new PagedList<T>(source, option);}#endregion#region IEnumerable<T> extensionspublic static IPagedList<T> ToPagedList<T>(this IEnumerable<T> source, IPagingOption option){return new PagedList<T>(source, option);}#endregion}
}
View Code

1.B.7,

1.C,下载地址返回顶部

 

warn作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/290423.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SignalR的使用

什么是 SignalR&#xff1f;ASP.NET Core SignalR 是一个开放源代码库&#xff0c;可用于简化向应用添加实时 Web 功能。实时 Web 功能使服务器端代码能够将内容推送到客户端。适合 SignalR 的候选项&#xff1a;需要从服务器进行高频率更新的应用。示例包括游戏、社交网络、投…

NHibernate之旅(7):初探NHibernate中的并发控制

本节内容 什么是并发控制&#xff1f; 悲观并发控制(Pessimistic Concurrency)乐观并发控制(Optimistic Concurrency)NHibernate支持乐观并发控制实例分析结语什么是并发控制&#xff1f; 当很多人试图同一时候改动数据库中的数据时&#xff0c;必须实现一个控制系统&#xff0…

期望DP

期望DP的一般做法是从末状态開始递推&#xff1a; Problem DescriptionAkemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, she is trapped in a labyrinth …

神奇的[Caller*]属性

前言上次&#xff0c;我们《使用 CallerArgumentExpression 检查弃元参数》&#xff0c;它实际是利用编译器编译时将变量名称传入。其实&#xff0c;.NET中提供了多个[Caller*]属性&#xff0c;帮助我们轻松获取调用者信息。CallerFilePathAttribute允许获取包含调用方的源文件…

java dateTime + long

2019独角兽企业重金招聘Python工程师标准>>> public static void main(String[] args) throws Exception{SimpleDateFormat sdfnew SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // long timeStartsdf.parse("2011-09-20 12:30:45").getTime();l…

.NET Core中异常过滤器ExceptionFilter的使用介绍

介绍实现需要继承IExceptionFilter 或 IAsyncExceptionFilter。可用于实现常见的错误处理策略。使用场景首先讲一下我们为什么要使用异常过滤器 &#xff0c;如果业务场景复杂&#xff0c;只使用HttpStatusCode&#xff0c;抛出异常后,后期要加很多字段来描述。那么这种就比较不…

程序一启动检查网络,如果没有网络就退出程序

转载于:https://www.cnblogs.com/songxing10000/p/4823812.html

看小说的这些年

从大一开始&#xff0c;就开始看起了小说&#xff0c;不是那种名著类型&#xff0c;而是快餐小说&#xff0c;玄幻、都市、言情、科幻&#xff0c;什么都会看&#xff0c;因为看多了&#xff0c;就会发现&#xff0c;已经没什么可以看的。 谈起快餐小说&#xff0c;已经有很多被…

COMA(一): Learning to Communicate with Deep Multi-Agent Reinforcement Learning 论文讲解

Learning to Communicate with Deep Multi-Agent Reinforcement Learning 论文讲解 论文链接&#xff1a;https://papers.nips.cc/paper/6042-learning-to-communicate-with-deep-multi-agent-reinforcement-learning.pdf &#xff08;这篇论文是COMA三部曲中的第&#xff08…

C和指针之指针数组和指向数组的指针

1、指针数组 定义一个指针数组&#xff0c;该数组中每个元素是一个指针&#xff0c;每个指针指向哪里就需要程序中后续再定义int *p[10]; 2、指向数组的指针 定义一个数组指针&#xff0c;该指针指向含10个元素的一维数组&#xff08;数组中每个元素是int型&#xff09;int (*p…

SSH 远程执行任务

SSH 是 Linux 下进行远程连接的基本工具&#xff0c;但是如果仅仅用它来登录那可是太浪费啦&#xff01;SSH 命令可是完成远程操作的神器啊&#xff0c;借助它我们可以把很多的远程操作自动化掉&#xff01;下面就对 SSH 的远程操作功能进行一个小小的总结。远程执行命令如果我…

分库分表之历史表如何选择最佳分片路由规则

前言先别急着关闭,我相信这篇文章应该是所有讲分表分库下的人都没有和你们讲过的一种分片模式,外面的文章基本上都是教你如何从零开始分片,现在我将讲解的是如何从1开始分片项目地址github地址 https://github.com/dotnetcore/sharding-coregitee地址 https://gitee.com/dotnet…

COMA(二):Counterfactual Multi-Agent Policy Gradients 论文讲解

Counterfactual Multi-Agent Policy Gradients 论文链接&#xff1a;https://arxiv.org/pdf/1705.08926.pdf 1. 问题提出&#xff08;解决了什么问题&#xff1f;&#xff09; 在现实世界中&#xff0c;有非常多的问题需要多个单位之间的“合作”才能完成任务&#xff0c;这就…

lecture6-mini批量梯度训练及三个加速的方法

Hinton的第6课&#xff0c;这一课中最后的那个rmsprop&#xff0c;关于它的资料&#xff0c;相对较少&#xff0c;差不多除了Hinton提出&#xff0c;没论文的样子&#xff0c;各位大大可以在这上面研究研究啊。 一、mini-批量梯度下降概述 这部分将介绍使用随机梯度下降学习来训…

Dapr集成之GRPC 接口

Dapr 为本地调用实现 HTTP 和 gRPC API 。通常大家第一时间想到的是通过 gRPC 调用 Dapr&#xff0c;更重要的一点是Dapr 也可以通过 gRPC 与应用程序通信。要做到这一点&#xff0c;原理很简单&#xff0c;应用程序需要托管一个gRPC服务器&#xff0c;并实现 Dapr 的GRPC 规范…

jQuery Validate验证框架详解

jQuery Validate验证框架详解 jQuery校验官网地址&#xff1a;http://bassistance.de/jquery-plugins/jquery-plugin-validation 一、导入js库 <script type"text/javascript" src"<%path %>/validate/jquery-1.6.2.min.js"></script> &…

RNN入门笔记

本笔记来源自Youtube李宏毅老师的RNN视频归纳&#xff0c;主要分为以下几个知识点: RNN 的特点RNN 的几种实现方法 (Simple RNN, LSTM)RNN 的训练不稳定性RNN 的keras实现 (定长和变长输入案例) Recurrent Neural Network Feature of RNN Differ from normal Neural Networ…

WPF 基础控件之 DatePicker 样式

此群已满340500857 &#xff0c;请加新群458041663由于微信群人数太多入群请添加小编微信号yanjinhuawechat 或 W_Feng_aiQ 邀请入群需备注WPF开发者 PS&#xff1a;有更好的方式欢迎推荐。支持NugetInstall-Package WPFDevelopers.Minimal -Version 3.2.001—代码如下一、创建…

stagefright框架(四)-Video Buffer传输流程

這篇文章將介紹Stagefright中是如何和OMX video decoder传送buffer。 (1) OMXCodec會在一開始的時候透過read函式來傳送未解碼的data給decoder&#xff0c;並且要求decoder將解碼後的data傳回來 status_t OMXCodec::read(...){ if (mInitialBufferSubmit) { mInitialBuffe…

微信支付四大支付模式分别有哪些区别?

微信支付是集成在微信客户端的支付功能&#xff0c;用户可以通过手机完成快速的支付流程。微信支付已为百货、餐厅、便利店、酒店、快递、景区、医院、售货机等提供了支付与营销的全方位支持。 目前微信支付已实现刷卡支付、扫码支付、公众号支付、APP支付&#xff0c;并提供企…