Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
1. fix repeat use same source
2. fix provider CreateQuery flow
3. fix except can compare all properties when no equalcomparerer
  • Loading branch information
oven425 committed Dec 17, 2021
1 parent a9937e5 commit 66e13cc
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 185 deletions.
36 changes: 22 additions & 14 deletions ConsoleApp1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public bool Equals(InstalledApp x, InstalledApp y)

public int GetHashCode(InstalledApp obj)
{
if (object.ReferenceEquals(obj, null)) return 0;
return obj.DisplayName == null ? 0 : obj.DisplayName.GetHashCode();
int hashcode = 0;
if (object.ReferenceEquals(obj, null))
{
hashcode = 0;
}
hashcode = obj.DisplayName == null ? 0 : obj.DisplayName.GetHashCode();
System.Diagnostics.Trace.WriteLine($"hashcode:{hashcode}");
return hashcode;
}
}

Expand Down Expand Up @@ -171,26 +177,28 @@ static void Main(string[] args)
.useSetting(x =>
{
x.Hive = RegistryHive.LocalMachine;
x.SubKey = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\";
x.SubKey = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\1A";
x.View = RegistryView.Registry64;
});
var yj = regt1.Take(2);
var aaaa = regt.Except(yj);
//var yj = regt1.Take(2);
//var aaaa = regt.Except(regt1.Take(2));
//var aaaa = regt.Where(x=>x.DisplayName!="").Except(regt1.Take(2));
//var aaaa = regt.Except(installs, new InstallAppCompare());
//var aaaa = regt.Except(installs);
var aaaa = regt.Except(regt.ToList().Take(2));
//var aaaa = regt.Select(x => x).Where(x => x.DisplayName != "");
foreach (var oo in aaaa)
{

}

var fir = regt.First();
//var ttk = regt.TakeWhile((x, index) => index == 0);
//int revv = regt.RemoveAll();
var tuple = regt.Select(x => Tuple.Create(x.DisplayName, x.EstimatedSize));
var tuple1 = regt.Select((x,idx) => Tuple.Create(x.DisplayName, idx));
var ssssz = regt.Where(x=>x.DisplayName=="AA").RemoveAll();
var group1 = regt.GroupBy(x => x.DisplayName, (key, reg) => reg);
var avg = regt.Where(x => int.Parse(x.EstimatedSize.ToString()).ToString("X2") == "6E").Select(x=>x.DisplayName);
//var fir = regt.First();
////var ttk = regt.TakeWhile((x, index) => index == 0);
////int revv = regt.RemoveAll();
//var tuple = regt.Select(x => Tuple.Create(x.DisplayName, x.EstimatedSize));
//var tuple1 = regt.Select((x,idx) => Tuple.Create(x.DisplayName, idx));
//var ssssz = regt.Where(x=>x.DisplayName=="AA").RemoveAll();
//var group1 = regt.Where(x=>x.DisplayName=="").GroupBy(x => x.DisplayName, (key, reg) => reg);
var avg = regt.Where(x => int.Parse(x.EstimatedSize.ToString()).ToString("X2") == "0A").Select(x=>x.DisplayName);
foreach(var oo in avg)
{

Expand Down
1 change: 0 additions & 1 deletion QSoft.Reg/QSoft.Registry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.XML" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
69 changes: 60 additions & 9 deletions QSoft.Reg/RegExpressionVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@ public Expression Visit(Expression node, Expression regfunc)
return expr;
}

Dictionary<Expression, Expression> m_Saves;
public Expression VisitA(Expression node, Expression regfunc, Dictionary<Expression, Expression> saves)
{
this.m_Saves = saves;
this.m_ExpressionSaves[node] = null;
this.m_RegSource = regfunc;
Expression expr = this.Visit(node);

var exprs = this.m_ExpressionSaves.Clone(expr);
expr = exprs.First().Value;
return expr;
}

public Expression Visit(MethodInfo method, params Expression[] nodes)
{
System.Diagnostics.Debug.WriteLine($"Visit {method?.Name}");
this.PreparMethod(nodes[1], new Expression[] { nodes[0], nodes[1] }, method);


Expression expr = this.Visit(nodes[1]);

Expand All @@ -35,6 +48,41 @@ public Expression Visit(MethodInfo method, params Expression[] nodes)
return expr;
}


public Expression Visit1(MethodCallExpression node, Expression[] args)
{
System.Diagnostics.Debug.WriteLine($"Visit {node.Method?.Name}");
this.PreparMethod(node, args, node.Method);

foreach(var arg in args)
{
var aaaa = this.Visit(arg);
}

var exprs = this.m_ExpressionSaves.Clone(node);
var ttypes = exprs.Select(x => x.Value).GetTypes(node.Method);
var mmm = Expression.Call(node.Method.GetGenericMethodDefinition().MakeGenericMethod(ttypes), exprs.Select(x => x.Value));
return mmm;
}

public Expression Visit2(MethodCallExpression node, Expression[] args)
{
System.Diagnostics.Debug.WriteLine($"Visit {node.Method?.Name}");
this.PreparMethod(node, args, node.Method);

foreach (var arg in args.Skip(1))
{
var aaaa = this.Visit(arg);
}

var exprs = this.m_ExpressionSaves.Clone(node);
var list = exprs.Select(x => x.Value).ToList();
list.Insert(0, args[0]);
var ttypes = list.GetTypes(node.Method);
var mmm = Expression.Call(node.Method.GetGenericMethodDefinition().MakeGenericMethod(ttypes), list);
return mmm;
}

protected override Expression VisitBinary(BinaryExpression node)
{
this.m_ExpressionSaves[node] = null;
Expand Down Expand Up @@ -457,7 +505,6 @@ void PreparMethod(Expression node, Expression[] args, MethodInfo method)
}
else
{
//this.m_GenericTypes.First()[dicc[i].Name] = null;
if (dic[i].ParameterType.IsGenericType == true)
{
this.m_GenericTypes.First()[dicc[i].Name] = dic[i].ParameterType.GetGenericArguments()[0];
Expand All @@ -483,7 +530,7 @@ void PreparMethod(Expression node, Expression[] args, MethodInfo method)
{
var return1 = method.ReturnType.GetGenericTypeDefinition();

if (return1 == typeof(IQueryable<>))
if (return1 == typeof(IQueryable<>)&& method.IsGenericMethod==true)
{
var t4 = method.GetGenericMethodDefinition().GetParameters();
string datatypename = t4.First().ParameterType.GetGenericArguments()[0].Name;
Expand Down Expand Up @@ -513,7 +560,12 @@ void PreparMethod(Expression node, Expression[] args, MethodInfo method)
protected override Expression VisitMethodCall(MethodCallExpression node)
{
System.Diagnostics.Debug.WriteLine($"VisitMethodCall {node.Method?.Name}");

if (this.m_Saves.ContainsKey(node) == true)
{
var aaa = this.m_Saves[node];
this.m_ExpressionSaves[node] = aaa;
return node;
}
this.PreparMethod(node, node.Arguments.ToArray(), node.Method);

var expr = base.VisitMethodCall(node) as MethodCallExpression;
Expand Down Expand Up @@ -603,12 +655,11 @@ protected override Expression VisitConstant(ConstantExpression node)

if (node.Type == typeof(RegQuery<TData>))
{
this.m_ExpressionSaves[expr] = this.m_RegSource;
var reguqery = node.Value as RegQuery<TData>;
var regprovider = reguqery?.Provider as RegProvider<TData>;
this.m_ExpressionSaves[expr] = regprovider.m_RegSource;
//this.m_ExpressionSaves[expr] = this.m_RegSource;
}
//else if (node.Type.Name.Contains("IEnumerable"))
//{
// this.m_ExpressionSaves[expr] = expr;
//}
else
{
this.m_ExpressionSaves[expr] = expr;
Expand Down
Loading

0 comments on commit 66e13cc

Please sign in to comment.