Browse Source

sort1

pull/720/head
2dust 5 years ago
parent
commit
fedfed4028
  1. 1
      v2rayN/v2rayN/Forms/MainForm.Designer.cs
  2. 16
      v2rayN/v2rayN/Forms/MainForm.cs
  3. 48
      v2rayN/v2rayN/Tool/QueryableExtension.cs
  4. 1
      v2rayN/v2rayN/v2rayN.csproj
  5. 2
      v2rayN/v2rayN/v2rayN.csproj.user

1
v2rayN/v2rayN/Forms/MainForm.Designer.cs generated

@ -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);

16
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");
}
}
}

48
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<T> OrderBy<T>(this IQueryable<T> query, string propertyName)
{
return _OrderBy<T>(query, propertyName, false);
}
public static IOrderedQueryable<T> OrderByDescending<T>(this IQueryable<T> query, string propertyName)
{
return _OrderBy<T>(query, propertyName, true);
}
static IOrderedQueryable<T> _OrderBy<T>(IQueryable<T> 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<T>)method.Invoke(null, new object[] { query, memberProp });
}
public static IOrderedQueryable<T> OrderByInternal<T, TProp>(IQueryable<T> query, PropertyInfo memberProperty)
{//public
return query.OrderBy(_GetLamba<T, TProp>(memberProperty));
}
public static IOrderedQueryable<T> OrderByDescendingInternal<T, TProp>(IQueryable<T> query, PropertyInfo memberProperty)
{//public
return query.OrderByDescending(_GetLamba<T, TProp>(memberProperty));
}
static Expression<Func<T, TProp>> _GetLamba<T, TProp>(PropertyInfo memberProperty)
{
if (memberProperty.PropertyType != typeof(TProp)) throw new Exception();
var thisArg = Expression.Parameter(typeof(T));
var lamba = Expression.Lambda<Func<T, TProp>>(Expression.Property(thisArg, memberProperty), thisArg);
return lamba;
}
}
}

1
v2rayN/v2rayN/v2rayN.csproj

@ -209,6 +209,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tool\FileManager.cs" />
<Compile Include="Tool\Job.cs" />
<Compile Include="Tool\QueryableExtension.cs" />
<Compile Include="Tool\UIRes.cs" />
<Compile Include="Tool\UI.cs" />
<Compile Include="Tool\Utils.cs" />

2
v2rayN/v2rayN/v2rayN.csproj.user

@ -9,7 +9,7 @@
<ErrorReportUrlHistory />
<FallbackCulture>zh-CN</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
<ProjectView>ShowAllFiles</ProjectView>
<ProjectView>ProjectFiles</ProjectView>
</PropertyGroup>
<PropertyGroup>
<EnableSecurityDebugging>false</EnableSecurityDebugging>

Loading…
Cancel
Save