From fedfed4028d828e793f9c72c49df8c750f2b6c9f Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 20 Apr 2020 21:19:00 +0800 Subject: [PATCH] sort1 --- v2rayN/v2rayN/Forms/MainForm.Designer.cs | 1 + v2rayN/v2rayN/Forms/MainForm.cs | 16 +++++++- v2rayN/v2rayN/Tool/QueryableExtension.cs | 48 ++++++++++++++++++++++++ v2rayN/v2rayN/v2rayN.csproj | 1 + v2rayN/v2rayN/v2rayN.csproj.user | 2 +- 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 v2rayN/v2rayN/Tool/QueryableExtension.cs diff --git a/v2rayN/v2rayN/Forms/MainForm.Designer.cs b/v2rayN/v2rayN/Forms/MainForm.Designer.cs index 4e516b81..7ec70cfe 100644 --- a/v2rayN/v2rayN/Forms/MainForm.Designer.cs +++ b/v2rayN/v2rayN/Forms/MainForm.Designer.cs @@ -165,6 +165,7 @@ this.lvServers.Name = "lvServers"; this.lvServers.UseCompatibleStateImageBehavior = false; this.lvServers.View = System.Windows.Forms.View.Details; + this.lvServers.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvServers_ColumnClick); this.lvServers.SelectedIndexChanged += new System.EventHandler(this.lvServers_SelectedIndexChanged); this.lvServers.Click += new System.EventHandler(this.lvServers_Click); this.lvServers.DoubleClick += new System.EventHandler(this.lvServers_DoubleClick); diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index a6b79333..57a2a2cc 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -178,7 +178,7 @@ namespace v2rayN.Forms lvServers.View = View.Details; lvServers.Scrollable = true; lvServers.MultiSelect = true; - lvServers.HeaderStyle = ColumnHeaderStyle.Nonclickable; + lvServers.HeaderStyle = ColumnHeaderStyle.Clickable; lvServers.Columns.Add("", 30); lvServers.Columns.Add(UIRes.I18N("LvServiceType"), 80); @@ -1563,8 +1563,22 @@ namespace v2rayN.Forms } + #endregion + private void lvServers_ColumnClick(object sender, ColumnClickEventArgs e) + { + if (e.Column < 0) + { + return; + } + //use linq + //var temp = config.vmess.AsQueryable(); + + //QueryableExtension + //temp.OrderBy("Code"); + // temp.OrderByDescending("Code"); + } } } diff --git a/v2rayN/v2rayN/Tool/QueryableExtension.cs b/v2rayN/v2rayN/Tool/QueryableExtension.cs new file mode 100644 index 00000000..eefb04d2 --- /dev/null +++ b/v2rayN/v2rayN/Tool/QueryableExtension.cs @@ -0,0 +1,48 @@ +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace v2rayN.Tool +{ + public static class QueryableExtension + { + public static IOrderedQueryable OrderBy(this IQueryable query, string propertyName) + { + return _OrderBy(query, propertyName, false); + } + public static IOrderedQueryable OrderByDescending(this IQueryable query, string propertyName) + { + return _OrderBy(query, propertyName, true); + } + + static IOrderedQueryable _OrderBy(IQueryable query, string propertyName, bool isDesc) + { + string methodname = (isDesc) ? "OrderByDescendingInternal" : "OrderByInternal"; + + var memberProp = typeof(T).GetProperty(propertyName); + + var method = typeof(QueryableExtension).GetMethod(methodname) + .MakeGenericMethod(typeof(T), memberProp.PropertyType); + + return (IOrderedQueryable)method.Invoke(null, new object[] { query, memberProp }); + } + public static IOrderedQueryable OrderByInternal(IQueryable query, PropertyInfo memberProperty) + {//public + return query.OrderBy(_GetLamba(memberProperty)); + } + public static IOrderedQueryable OrderByDescendingInternal(IQueryable query, PropertyInfo memberProperty) + {//public + return query.OrderByDescending(_GetLamba(memberProperty)); + } + static Expression> _GetLamba(PropertyInfo memberProperty) + { + if (memberProperty.PropertyType != typeof(TProp)) throw new Exception(); + + var thisArg = Expression.Parameter(typeof(T)); + var lamba = Expression.Lambda>(Expression.Property(thisArg, memberProperty), thisArg); + + return lamba; + } + } +} diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index 65075779..64ece7d3 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -209,6 +209,7 @@ + diff --git a/v2rayN/v2rayN/v2rayN.csproj.user b/v2rayN/v2rayN/v2rayN.csproj.user index a36e9eb4..778969a8 100644 --- a/v2rayN/v2rayN/v2rayN.csproj.user +++ b/v2rayN/v2rayN/v2rayN.csproj.user @@ -9,7 +9,7 @@ zh-CN false - ShowAllFiles + ProjectFiles false