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