diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs
index 8ebb3b4..048b49a 100644
--- a/ConsoleApp1/Program.cs
+++ b/ConsoleApp1/Program.cs
@@ -109,15 +109,23 @@ static void Main(string[] args)
x.SubKey = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\1A";
x.View = RegistryView.Registry64;
});
-
+ var group2 = regt.GroupBy(x => x.DisplayName, (key, app) => new { key, app });
+ var takewhile1 = regt.Where(x => x.DisplayName != "" && x.DisplayVersion > new Version(3,3,3,3));
+ var where1 = regt.Where(x => x.DisplayName != "").OrderByDescending(x=>x.DisplayVersion);
+ var aa = regt.GroupBy(x => x.DisplayVersion, (ver, app)=>new { ver, app});
+ regt.GroupBy(x=>x, (x,y)=>x).Update(x => new InstalledApp() { EstimatedSize = x.EstimatedSize - 100 });
+ //regt.Where(x => x.EstimatedSize > 130).Update(x => new InstalledApp() { EstimatedSize = x.EstimatedSize - 100 });
+ //var where_select = regt.Where(x => x.EstimatedSize > 130).Select((x, index) => x);
//var group1 = regt.GroupBy(x => x.DisplayName);
//var group2 = regt.GroupBy(x => x.DisplayName, x => x.EstimatedSize);
- var group3 = regt.GroupBy(x => x, (x,y)=>y);
- foreach(var oo in group3)
- {
+ //var group3 = regt.GroupBy(x => x.DisplayName, (y, z) => z);
+ //foreach (var oo in group3)
+ //{
- }
- var select = regt.Select((x, index) => new { x, index });
+ //}
+ //var where = regt.Where(x => x.DisplayName != ""&& x.EstimatedSize>0);
+ var zip = regt.Zip(installs, (reg, app) => reg);
+ var select = regt.Select((x, index) => index+1);
var any = regt.Any(x => x.EstimatedSize > 0);
var first1 = regt.First();
var first2 = regt.First(x => x.DisplayName != "");
diff --git a/QSoft.Reg/DictionaryList.cs b/QSoft.Reg/DictionaryList.cs
index 886741e..73cf945 100644
--- a/QSoft.Reg/DictionaryList.cs
+++ b/QSoft.Reg/DictionaryList.cs
@@ -14,6 +14,10 @@ public TValue this[TKey key]
get
{
int index = this.FindLastIndex(x => x.Key.Equals(key));
+ if(index < 0)
+ {
+ return default(TValue);
+ }
return this.ElementAt(index).Value;
}
set
diff --git a/QSoft.Reg/QSoft.Registry.csproj b/QSoft.Reg/QSoft.Registry.csproj
index 30ee587..84ac900 100644
--- a/QSoft.Reg/QSoft.Registry.csproj
+++ b/QSoft.Reg/QSoft.Registry.csproj
@@ -9,7 +9,7 @@
Properties
QSoft.Registry
QSoft.Registry
- v4.0
+ v4.8
512
true
diff --git a/QSoft.Reg/RegExpressionVisitor.cs b/QSoft.Reg/RegExpressionVisitor.cs
index 1a767c5..7a36cfb 100644
--- a/QSoft.Reg/RegExpressionVisitor.cs
+++ b/QSoft.Reg/RegExpressionVisitor.cs
@@ -17,7 +17,6 @@ public Expression Visit(Expression node, Type datatype, Expression regfunc)
this.m_ExpressionSaves[node] = null;
this.m_DataType = datatype;
this.m_RegSource = regfunc;
- Type ttupe = regfunc.GetType();
Expression expr = this.Visit(node);
var exprs = this.m_ExpressionSaves.Clone(expr);
@@ -25,6 +24,19 @@ public Expression Visit(Expression node, Type datatype, Expression regfunc)
return expr;
}
+ public Expression Visit(Type datatype, MethodInfo method, params Expression[] nodes)
+ {
+ System.Diagnostics.Trace.WriteLine($"Visit {method?.Name}");
+ this.PreparMethod(nodes[1], new Expression[] { nodes[0], nodes[1] }, method);
+ this.m_DataType = datatype;
+
+ Expression expr = this.Visit(nodes[1]);
+
+ var exprs = this.m_ExpressionSaves.Clone(expr);
+ expr = exprs.First().Value;
+ return expr;
+ }
+
protected override Expression VisitBinary(BinaryExpression node)
{
this.m_ExpressionSaves[node] = null;
@@ -58,7 +70,7 @@ protected override Expression VisitNew(NewExpression node)
{
if (parameter.Name == this.m_DataTypeName)
{
- if (parameter.Type.IsGenericType == true && parameter.Type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
+ if (parameter.Type.IsGenericType == true)
{
var param = this.m_Parameters[parameter.Name];
var select_method = this.m_DataType.SelectMethod_Enumerable();
@@ -73,6 +85,16 @@ protected override Expression VisitNew(NewExpression node)
exprs[exprs.ElementAt(i).Key] = todata;
}
}
+ else
+ {
+ var param = this.m_Parameters[parameter.Name];
+ if(param.Type == this.m_DataType)
+ {
+ var todata = this.m_DataType.ToData(param);
+ exprs[exprs.ElementAt(i).Key] = todata;
+ }
+
+ }
}
}
if (expr.Members == null)
@@ -133,6 +155,24 @@ protected override MemberAssignment VisitMemberAssignment(MemberAssignment node)
protected override Expression VisitLambda(Expression node)
{
this.m_ExpressionSaves[node] = null;
+ if(this.m_ExpressionSaves1.Count == 0)
+ {
+ //var pps1 = pp1.GetGenericArguments();
+ //for (int i = 0; i < node.Parameters.Count; i++)
+ //{
+ // this.m_ExpressionSaves1[node.Parameters[i]] = pps1[i];
+ //}
+ }
+ else
+ {
+ var pp1 = this.m_ExpressionSaves1[node];
+ var pps1 = pp1.GetGenericArguments();
+ for (int i = 0; i < node.Parameters.Count; i++)
+ {
+ this.m_ExpressionSaves1[node.Parameters[i]] = pps1[i];
+ }
+ }
+
System.Diagnostics.Trace.WriteLine($"VisitLambda T:{typeof(T)}");
if(m_PP != null)
{
@@ -200,12 +240,12 @@ protected override Expression VisitLambda(Expression node)
m_Lambda = lambda;
}
this.m_Parameters.Clear();
- this.m_ReturnType = this.m_Lambda.ReturnType;
+ this.ReturnType = this.m_Lambda.ReturnType;
this.m_Lastnode = expr;
return expr;
}
- Type m_ReturnType = null;
+ public Type ReturnType { set; get; } = null;
Dictionary m_Parameters = new Dictionary();
protected override Expression VisitParameter(ParameterExpression node)
@@ -213,70 +253,96 @@ protected override Expression VisitParameter(ParameterExpression node)
m_ExpressionSaves[node] = null;
System.Diagnostics.Trace.WriteLine($"VisitParameter {node.Type.Name}");
var expr = base.VisitParameter(node) as ParameterExpression;
- if (expr.Name == this.m_DataTypeName)
+ var pp1 = this.m_ExpressionSaves1[expr];
+ //if(this.m_Lastnode != null)
{
if (this.m_Parameters.ContainsKey(expr.Name) == false)
{
- ParameterExpression pp = null;
-
- if (expr.Type.IsGenericType == true&&expr.Type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
+ if(pp1.IsGenericType == true&&pp1.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
- pp = Expression.Parameter(typeof(IEnumerable), expr.Name);
+ var type = this.m_GenericTypes[pp1.GetGenericArguments()[0].Name];
+ var ie = pp1.GetGenericTypeDefinition().MakeGenericType(type);
+ var pp = Expression.Parameter(ie, expr.Name);
+ this.m_Parameters[expr.Name] = pp;
}
- else
+ else if(this.m_GenericTypes.ContainsKey(pp1.Name) == true)
{
- pp = Expression.Parameter(typeof(RegistryKey), expr.Name);
- }
-
- this.m_Parameters.Add(pp.Name, pp);
- this.m_ExpressionSaves[expr] = pp;
- }
- }
- else if (expr.Type == this.m_DataType)
- {
- if (this.m_Parameters.ContainsKey(expr.Name) == false)
- {
- if(string.IsNullOrEmpty(this.m_DataTypeName))
- {
- var parameter = Expression.Parameter(typeof(RegistryKey), expr.Name);
- this.m_Parameters.Add(parameter.Name, parameter);
- this.m_ExpressionSaves[expr] = parameter;
+ var type = this.m_GenericTypes[pp1.Name];
+ var pp = Expression.Parameter(type, expr.Name);
+ this.m_Parameters[expr.Name] = pp;
}
else
{
- this.m_Parameters.Add(expr.Name, expr);
- this.m_ExpressionSaves[expr] = expr;
+ this.m_Parameters[expr.Name] = expr;
}
+
}
+ this.m_ExpressionSaves[expr] = this.m_Parameters[expr.Name];
}
- else if(expr.Type.Name.Contains("IGrouping"))
- {
- var args = expr.Type.GetGenericArguments();
- args.Replace(this.m_DataType, typeof(RegistryKey));
- var parameter = Expression.Parameter(typeof(IGrouping<, >).MakeGenericType(args), expr.Name);
- if(this.m_Parameters.ContainsKey(parameter.Name) == false)
- {
- this.m_Parameters[parameter.Name]= parameter;
- this.m_ExpressionSaves[expr] = parameter;
- }
- }
- else
- {
- if (this.m_Parameters.Count ==0)
- {
- this.m_Parameters.Add(expr.Name, expr);
- this.m_ExpressionSaves[expr] = expr;
- }
- else if(this.m_Parameters.ContainsKey(expr.Name)==false)
- {
- this.m_Parameters.Add(expr.Name, expr);
- this.m_ExpressionSaves[expr] = expr;
- }
- }
- if(this.m_ExpressionSaves[node] == null)
- {
- this.m_ExpressionSaves[node] = this.m_Parameters[node.Name];
- }
+ //if (expr.Name == this.m_DataTypeName)
+ //{
+ // if (this.m_Parameters.ContainsKey(expr.Name) == false)
+ // {
+ // ParameterExpression pp = null;
+
+ // if (expr.Type.IsGenericType == true&&expr.Type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
+ // {
+ // pp = Expression.Parameter(typeof(IEnumerable), expr.Name);
+ // }
+ // else
+ // {
+ // pp = Expression.Parameter(typeof(RegistryKey), expr.Name);
+ // }
+
+ // this.m_Parameters.Add(pp.Name, pp);
+ // this.m_ExpressionSaves[expr] = pp;
+ // }
+ //}
+ //else if (expr.Type == this.m_DataType)
+ //{
+ // if (this.m_Parameters.ContainsKey(expr.Name) == false)
+ // {
+ // if(string.IsNullOrEmpty(this.m_DataTypeName))
+ // {
+ // var parameter = Expression.Parameter(typeof(RegistryKey), expr.Name);
+ // this.m_Parameters.Add(parameter.Name, parameter);
+ // this.m_ExpressionSaves[expr] = parameter;
+ // }
+ // else
+ // {
+ // this.m_Parameters.Add(expr.Name, expr);
+ // this.m_ExpressionSaves[expr] = expr;
+ // }
+ // }
+ //}
+ //else if(expr.Type.Name.Contains("IGrouping"))
+ //{
+ // var args = expr.Type.GetGenericArguments();
+ // args.Replace(this.m_DataType, typeof(RegistryKey));
+ // var parameter = Expression.Parameter(typeof(IGrouping<, >).MakeGenericType(args), expr.Name);
+ // if(this.m_Parameters.ContainsKey(parameter.Name) == false)
+ // {
+ // this.m_Parameters[parameter.Name]= parameter;
+ // this.m_ExpressionSaves[expr] = parameter;
+ // }
+ //}
+ //else
+ //{
+ // if (this.m_Parameters.Count ==0)
+ // {
+ // this.m_Parameters.Add(expr.Name, expr);
+ // this.m_ExpressionSaves[expr] = expr;
+ // }
+ // else if(this.m_Parameters.ContainsKey(expr.Name)==false)
+ // {
+ // this.m_Parameters.Add(expr.Name, expr);
+ // this.m_ExpressionSaves[expr] = expr;
+ // }
+ //}
+ //if(this.m_ExpressionSaves[node] == null)
+ //{
+ // this.m_ExpressionSaves[node] = this.m_Parameters[node.Name];
+ //}
this.m_Lastnode = expr;
return expr;
}
@@ -284,7 +350,6 @@ protected override Expression VisitParameter(ParameterExpression node)
protected override Expression VisitMember(MemberExpression node)
{
m_ExpressionSaves[node] = null;
- //m_ExpressionSaves.Add(new Tr() { Src = node });
var ttyp = node.Type;
System.Diagnostics.Trace.WriteLine($"VisitMember {node.Member.Name}");
var expr = base.VisitMember(node) as MemberExpression;
@@ -328,7 +393,8 @@ protected override Expression VisitMember(MemberExpression node)
return expr;
}
- Tuple m_PP;
+ Tuple m_PP = null;
+ Dictionary m_GenericTypes = new Dictionary();
protected override Expression VisitUnary(UnaryExpression node)
{
m_PP = null;
@@ -337,10 +403,35 @@ protected override Expression VisitUnary(UnaryExpression node)
m_PP = m_PPs[node];
}
this.m_ExpressionSaves[node] = null;
+ if(this.m_ExpressionSaves1.ContainsKey(node) == true)
+ {
+ var pp1 = this.m_ExpressionSaves1[node];
+ if (pp1 != null)
+ {
+ this.m_ExpressionSaves1[node.Operand] = pp1.GetGenericArguments()[0];
+ }
+ }
+
System.Diagnostics.Trace.WriteLine($"VisitUnary");
var expr = base.VisitUnary(node);
var exprs = this.m_ExpressionSaves.Clone(expr);
+
+ if(this.m_ExpressionSaves1.ContainsKey(expr) == true)
+ {
+ var pp = this.m_ExpressionSaves1[expr];
+ if (pp != null)
+ {
+ var kkey = pp.GetGenericArguments()[0].GetGenericArguments().Last().Name;
+ var lambda = exprs.First().Value as LambdaExpression;
+ if (lambda != null)
+ {
+ this.m_GenericTypes[kkey] = lambda.ReturnType;
+ this.m_Parameters.Clear();
+ }
+ }
+ }
+
Type result_type = expr.Type;
if (result_type.IsGenericType == true)
{
@@ -352,28 +443,55 @@ protected override Expression VisitUnary(UnaryExpression node)
UnaryExpression unary = Expression.MakeUnary(node.NodeType, exprs.First().Value, result_type);
this.m_ExpressionSaves[expr] = unary;
-
+
this.m_Lastnode = expr;
return expr;
}
- //Stack> m_ParamList = new Stack>();
- Dictionary> m_PPs = new Dictionary>();
- DictionaryList m_ExpressionSaves = new DictionaryList();
- Expression m_Lastnode = null;
- Dictionary GenericTypes = new Dictionary();
- protected override Expression VisitMethodCall(MethodCallExpression node)
+ void PreparMethod(Expression node, Expression[] args, MethodInfo method)
{
m_ExpressionSaves[node] = null;
- System.Diagnostics.Trace.WriteLine($"VisitMethodCall {node.Method?.Name}");
- if (node.Method.ReturnType.IsGenericType == true)
+ System.Diagnostics.Trace.WriteLine($"PreparMethod {method?.Name}");
+
+ if (method.IsGenericMethod == true)
{
- var return1 = node.Method.ReturnType.GetGenericTypeDefinition();
-
+ var dic = method.GetParameters();
+ var dicc = method.GetGenericMethodDefinition().GetGenericArguments();
+ for (int i = 0; i < dicc.Length; i++)
+ {
+ if (i == 0)
+ {
+ this.m_GenericTypes[dicc[i].Name] = typeof(RegistryKey);
+ }
+ else
+ {
+ if (dic[i].ParameterType.IsGenericType == true && dic[i].ParameterType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
+ {
+ this.m_GenericTypes[dicc[i].Name] = dic[i].ParameterType.GetGenericArguments()[0];
+ }
+ else
+ {
+ this.m_GenericTypes[dicc[i].Name] = null;
+ }
+ }
+ }
+
+
+ var dic2 = method.GetGenericMethodDefinition().GetParameters();
+ for (int i = 0; i < args.Length; i++)
+ {
+ m_ExpressionSaves1[args[i]] = dic2[i].ParameterType;
+ }
+ }
+
+
+ if (method.ReturnType.IsGenericType == true)
+ {
+ var return1 = method.ReturnType.GetGenericTypeDefinition();
+
if (return1 == typeof(IQueryable<>))
{
-
- var t4 = node.Method.GetGenericMethodDefinition().GetParameters();
+ var t4 = method.GetGenericMethodDefinition().GetParameters();
string datatypename = t4.First().ParameterType.GetGenericArguments()[0].Name;
for (int i = 0; i < t4.Length; i++)
{
@@ -385,12 +503,24 @@ protected override Expression VisitMethodCall(MethodCallExpression node)
}
if (invoke != null)
{
- m_PPs[node.Arguments[i]] = Tuple.Create(t4[i], invoke, datatypename);
+ m_PPs[args[i]] = Tuple.Create(t4[i], invoke, datatypename);
}
}
}
}
-
+ }
+
+
+ Dictionary> m_PPs = new Dictionary>();
+ DictionaryList m_ExpressionSaves = new DictionaryList();
+ Dictionary m_ExpressionSaves1 = new Dictionary();
+ Expression m_Lastnode = null;
+ Dictionary GenericTypes = new Dictionary();
+ protected override Expression VisitMethodCall(MethodCallExpression node)
+ {
+ System.Diagnostics.Trace.WriteLine($"VisitMethodCall {node.Method?.Name}");
+ this.PreparMethod(node, node.Arguments.ToArray(), node.Method);
+
var expr = base.VisitMethodCall(node) as MethodCallExpression;
var exprs1 = this.m_ExpressionSaves.Clone(expr);
@@ -447,7 +577,6 @@ protected override Expression VisitMethodCall(MethodCallExpression node)
}
- //Expression m_ConstantExpression_Value = null;
protected override Expression VisitConstant(ConstantExpression node)
{
this.m_ExpressionSaves[node] = null;
@@ -464,13 +593,10 @@ protected override Expression VisitConstant(ConstantExpression node)
}
else if (node.Type.Name.Contains("IEnumerable"))
{
- //this.m_ParamList.Push(Tuple.Create(expr.Type.GetGenericArguments()[0], expr));
this.m_ExpressionSaves[expr] = expr;
}
else
{
- //this.m_ParamList.Push(Tuple.Create(node.Type, expr));
- //m_ConstantExpression_Value = expr;
this.m_ExpressionSaves[expr] = expr;
}
this.m_Lastnode = expr;
diff --git a/QSoft.Reg/RegProvider.cs b/QSoft.Reg/RegProvider.cs
index 471e459..9fed331 100644
--- a/QSoft.Reg/RegProvider.cs
+++ b/QSoft.Reg/RegProvider.cs
@@ -67,7 +67,7 @@ public IQueryable CreateQuery(Expression expression)
}
if (bb == true)
{
- expr = reg.Visit(method1.Arguments[1], this.m_DataType, this.m_RegSource);
+ expr = reg.Visit(this.m_DataType, method1.Method, method1.Arguments[0], method1.Arguments[1]);
var methods = method1.Method.ReflectedType.GetMethods().Where(x => x.Name == method1.Method.Name);
methods = methods.Where(x => x.IsGenericMethod == method1.Method.IsGenericMethod);
@@ -76,6 +76,7 @@ public IQueryable CreateQuery(Expression expression)
if (pps[0] == this.m_DataType)
{
pps[0] = typeof(RegistryKey);
+ pps[pps.Length-1] = reg.ReturnType;
}
if (pps[0].Name.Contains("IGrouping"))
{
@@ -100,7 +101,7 @@ public IQueryable CreateQuery(Expression expression)
var ooi = methods.ElementAt(0).MakeGenericMethod(pps);
var ppps = method1.Method.GetGenericMethodDefinition().GetParameters();
ooi = method1.Method.GetGenericMethodDefinition().MakeGenericMethod(pps);
- if(this.m_RegMethod.Type != ooi.ReturnType)
+ //if(this.m_RegMethod.Type != ooi.ReturnType)
{
this.m_RegMethod = Expression.Call(ooi, this.m_RegMethod, expr);
}
@@ -279,7 +280,8 @@ public TResult Execute(Expression expression)
for (int i=1; i< updatemethod.Arguments.Count; i++)
{
RegExpressionVisitor regvisitor = new RegExpressionVisitor();
- arg1 = regvisitor.Visit(updatemethod.Arguments[i], this.m_DataType, this.m_RegSource);
+ //arg1 = regvisitor.Visit(updatemethod.Arguments[i], this.m_DataType, this.m_RegSource);
+ arg1 = regvisitor.Visit(this.m_DataType, updatemethod.Method, updatemethod.Arguments[i-1], updatemethod.Arguments[i]);
args.Add(arg1);
}
diff --git a/QSoft.Registry.nuspec b/QSoft.Registry.nuspec
index 5ddd9f0..77e76af 100644
--- a/QSoft.Registry.nuspec
+++ b/QSoft.Registry.nuspec
@@ -2,7 +2,7 @@
QSoft.Registry
- 1.0.0.2
+ 1.0.0.3
Registry.NET
BEN_HSU
BEN_HSU
@@ -11,7 +11,7 @@
https://licenses.nuget.org/MIT
47811249682_f903175a23_o.jpg
https://github.com/oven425/QSoft.Registry
- Use linq read RegistryKey
+ Linq for RegistryKey
Copyright © Ben Hsu 2021
@@ -19,6 +19,8 @@
+ 1. Fix parse Expression issue
+2. Fix data type translate issue
diff --git a/README.md b/README.md
index 1ac4afe..af8d5f4 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,14 @@
-
-
# Use Linq style read registry(Linq to Registry)
## Use Queryable read data
-* Full Linq support
- provide Queryable function
-* Auto control Registry resource
- no control resource create and dispose
-## sample code
+* Support Queryable function
+* Auto control Registry resource no control resource create and dispose
+* Support Update RegistryKey
+## Sample code
Create definition
```csharp
public class InstalledApp
{
- public string DisplayName { set; get; }
+ public string DisplayName { set; get; }
public string DisplayVersion { set; get; }
public int? EstimatedSize { set; get; }
}
@@ -19,20 +16,20 @@ public class InstalledApp
Create Query
```csharp
var regt = new RegQuery()
- .useSetting(x =>
- {
- x.Hive = RegistryHive.LocalMachine;
- x.SubKey = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
- });
+ .useSetting(x =>
+ {
+ x.Hive = RegistryHive.LocalMachine;
+ x.SubKey = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
+ x.View = RegistryView.Registry64;
+ });
```
-Query data
+Get data
```csharp
var first1 = regt.First();
var first2 = regt.First(x => x.DisplayName != "");
var last1 = regt.Last();
var last2 = regt.Last(x => x.DisplayName != "");
-var take = regt.Take(10);
-var takewhile = regt.TakeWhile(x => x.DisplayName == "AA");
+
var count1 = regt.Count();
var count2 = regt.Count(x => x.DisplayName == "AA");
@@ -41,8 +38,6 @@ var any = regt.Any(x => x.EstimatedSize > 0);
var reverse = regt.Reverse();
var average = regt.Average(x => x.EstimatedSize);
var sum = regt.Sum(x => x.EstimatedSize);
-var skip1 = regt.Skip(1);
-var skipwhile = regt.SkipWhile(x => x.DisplayName == "B");
var min = regt.Min(x => x.EstimatedSize);
var max = regt.Max(x => x.EstimatedSize);
@@ -51,42 +46,23 @@ var tolist = regt.ToList();
var toarray = regt.ToArray();
var dictonary = regt.ToDictionary(x => x.EstimatedSize);
```
+Query data
```csharp
-var orderbydesc = regt.OrderByDescending(x => x.EstimatedSize);
+var take = regt.Take(10);
+var takewhile = regt.TakeWhile(x => x.DisplayVersion <= new Version(2,2,2,2));
+var orderbydesc = regt.OrderByDescending(x => x.DisplayVersion);
var oderby = regt.OrderBy(x => x.EstimatedSize);
-var where1 = regt.Where(x => x.DisplayName != "");
-```
-Join data definition and create
-```csharp
-public class AppData
-{
- public AppData()
- {
-
- }
-
- public AppData(string name)
- {
- this.Name = name;
- }
- public string Name { set; get; }
- public string Ver { set; get; }
- public string Uninstallstring { set; get; }
- public bool IsOfficial { set; get; }
-}
-```
-```csharp
-List apps = new List();
-apps.Add(new AppData() { Name = "A", IsOfficial = true });
-apps.Add(new AppData() { Name = "AA", IsOfficial = false });
+var where = regt.Where(x => x.DisplayName != "" && x.DisplayVersion > new Version(3,3,3,3));
```
+GroupBy Data
```csharp
-var join1 = regt.Join(apps, x => x.DisplayName, y => y.Name, (x, y) => new { x.DisplayName, x.EstimatedSize, y.IsOfficial });
-var groupjoin = regt.GroupJoin(apps, x => x.DisplayName, y => y.Name, (x, y) => x);
+var group1 = regt.GroupBy(x => x.DisplayName);
+var group2 = regt.GroupBy(x => x.DisplayName, (key, app) => new { key, app });
```
+
## Use extension linq function like below code
```csharp
using QSoft.Registry;
diff --git a/UnitTestProject1/UnitTest1.cs b/UnitTestProject1/UnitTest1.cs
index b6b9702..1bab441 100644
--- a/UnitTestProject1/UnitTest1.cs
+++ b/UnitTestProject1/UnitTest1.cs
@@ -127,10 +127,9 @@ public void GroupBy()
this.Check(this.m_Tests.GroupBy(x => new { x.IsOfficial, x.DisplayName }), regt.GroupBy(x => new { x.IsOfficial, x.DisplayName }));
this.Check(this.m_Tests.GroupBy(x => x), regt.GroupBy(x => x));
this.Check(this.m_Tests.GroupBy(x => x.DisplayName, x => x.DisplayName), regt.GroupBy(x => x.DisplayName, x => x.DisplayName));
- this.Check(this.m_Tests.GroupBy(x => x), regt.GroupBy(x => x));
- this.Check(this.m_Tests.GroupBy(x => x).Select(x => x), regt.GroupBy(x => x).Select(x => x));
- this.Check(this.m_Tests.GroupBy(x => x).Select(x => x.Key), regt.GroupBy(x => x).Select(x => x.Key));
- this.Check(this.m_Tests.GroupBy(x => x.DisplayName).Select(x => x.Key), regt.GroupBy(x => x.DisplayName).Select(x => x.Key));
+ //this.Check(this.m_Tests.GroupBy(x => x).Select(x => x), regt.GroupBy(x => x).Select(x => x));
+ //this.Check(this.m_Tests.GroupBy(x => x).Select(x => x.Key), regt.GroupBy(x => x).Select(x => x.Key));
+ //this.Check(this.m_Tests.GroupBy(x => x.DisplayName).Select(x => x.Key), regt.GroupBy(x => x.DisplayName).Select(x => x.Key));
}
void Check(IEnumerable> src, IEnumerable> dst)
@@ -196,6 +195,11 @@ public void SkipWhile_Index()
this.Check(this.m_Tests.SkipWhile((x,index) => x.EstimatedSize > 20), regt.SkipWhile((x,index) => x.EstimatedSize > 20));
}
+ [TestMethod]
+ public void Where_All()
+ {
+ }
+
[TestMethod]
public void Where()
{
@@ -213,7 +217,7 @@ public void Where()
this.Check(this.m_Tests.Where(x => x.EstimatedSize.ToString() == $"{x.EstimatedSize}"), regt.Where(x => x.EstimatedSize.ToString() == $"{x.EstimatedSize}"));
this.Check(this.m_Tests.Where(x => x.EstimatedSize.ToString() == $"{x.EstimatedSize}"), regt.Where(x => x.EstimatedSize.ToString() == $"{x.EstimatedSize}"));
-
+ this.Check(this.m_Tests.Where(x=>x.DisplayName.Contains("A")).Select(x => $"IsOfficial{x.IsOfficial}"), regt.Where(x => x.DisplayName.Contains("A")).Select(x => $"IsOfficial{x.IsOfficial}"));
//this.Check(this.m_Tests.Where(x => x.FC() == 100), regt.Where(x => x.FC() == 100));
}
@@ -280,18 +284,12 @@ public void Select()
this.Check(this.m_Tests.Select(x => new { Size = x.EstimatedSize }), regt.Select(x => new { Size = x.EstimatedSize }));
this.Check(this.m_Tests.Select(x => new { Official = x.IsOfficial }), regt.Select(x => new { Official = x.IsOfficial }));
this.Check(this.m_Tests.Select(x => $"IsOfficial{x.IsOfficial}"), regt.Select(x => $"IsOfficial{x.IsOfficial}"));
- //this.m_Tests.Select(x => new AppData(x.DisplayName) { Ver = x.DisplayVersion.ToString(), IsOfficial=(bool)x.IsOfficial });
this.Check(this.m_Tests.Select(x => new AppData(x.DisplayName) { Ver = x.DisplayVersion.ToString(), IsOfficial = (bool)x.IsOfficial }), regt.Select(x => new AppData(x.DisplayName) { IsOfficial = (bool)x.IsOfficial, Ver = x.DisplayVersion.ToString() }));
}
[TestMethod]
public void Select_Index()
{
- var select = regt.Select((x,index) => x);
- foreach(var oo in select)
- {
-
- }
this.Check(this.m_Tests.Select((x, index) => x), regt.Select((x, index) => x));
this.Check(this.m_Tests.Select((x, index) => new { x, index }), regt.Select((x, index) => new { x, index }));
}