object GetRightfulValue(Expression e, object val) { object tempVal; if (e.Type.TryChangeValueType(val, out tempVal)) { return(tempVal); } else { //如果val为IEnumerable那么不需要转换 if (val is IEnumerable) { return(val); } OtherParser.TryParse(e, out val); return(val); } }
public bool TryParse(Expression e, out object val, MemberInfo memberInfo = null, IReadOnlyList <Expression> args = null) { bool bOther = false; if (MethodCallParser.TryParse(e, out val, memberInfo, args)) { } else if (MemberParser.TryParse(e, out val, memberInfo, args)) { } else if (ConstParser.TryParse(e, out val, memberInfo, args)) { } else if (NewArrayParser.TryParse(e, out val, memberInfo, args)) { //解析出来之后,显示的数据依然是:Trim(value(System.Char[])) //在EF的Where中是不支持l.name.Trim('_')这样的操作的,只能支持:l.name.Trim() //但是还是需要进行解析,不然会交由OtherParser(DynamicParser)进行解析了 } else if (UnaryParser.TryParse(e, out val, memberInfo, args)) { } else { bOther = true; OtherParser.TryParse(e, out val, memberInfo, args); } //不是OtherParser解析的,而且val不为null,判断val的类型与Expression.Type的类型是否一致 if (!bOther && val != null) { val = GetRightfulValue(e, val); } return(true); }
private static void Main(string[] args) { var directory = args[0]; if (!Directory.Exists(directory)) { Console.Error.WriteLine("Path {0} does not exist. Please provide a path with bank statements", args[0]); return; } var result = Directory .GetFiles(directory, "*.pdf") .SelectMany(Utilities.Parse) .OrderBy(l => l.TransactionDate) .Where(l => l.TransactionDate.Year == 2018) .ToList(); var x = OtherParser.ReadDataxCsv(@"S:\FellesRegnskap\2018\Kontoutskrift\datax.csv"); var(fir, la) = Utilities.CompareListe(result, x); Console.WriteLine("First {0} of {1}", fir.Count, result.Count); foreach (var r in fir) { Console.WriteLine(r); } Console.WriteLine("\nSecond {0} of {1}", la.Count, x.Count); foreach (var r in la) { Console.WriteLine(r); } Console.ReadLine(); }