-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathExcelQueryable.cs
More file actions
44 lines (38 loc) · 1.62 KB
/
ExcelQueryable.cs
File metadata and controls
44 lines (38 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections.Generic;
using System.Linq;
using Remotion.Linq;
using System.Linq.Expressions;
using LinqToExcel.Attributes;
using System;
using LinqToExcel.Logging;
using Remotion.Linq.Parsing.Structure;
namespace LinqToExcel.Query
{
public class ExcelQueryable<T> : QueryableBase<T>
{
private static IQueryExecutor CreateExecutor(ExcelQueryArgs args, ILogManagerFactory logManagerFactory)
{
return new ExcelQueryExecutor(args, logManagerFactory);
}
// This constructor is called by users, create a new IQueryExecutor.
internal ExcelQueryable(ExcelQueryArgs args, ILogManagerFactory logManagerFactory)
: base( QueryParser.CreateDefault(), CreateExecutor(args, logManagerFactory) )
{
foreach (var property in typeof(T).GetProperties())
{
ExcelColumnAttribute att = (ExcelColumnAttribute)Attribute.GetCustomAttribute(property, typeof(ExcelColumnAttribute));
if (att != null && !args.ColumnMappings.ContainsKey(property.Name))
{
var columnNames = ExcelUtilities.GetColumnNames(args);
args.ColumnMappings.Add(property.Name, !att.IsForced ?
att.ColumnName :
columnNames.ToList().Find(x => att.HasSimilarColumn(x))??att.ColumnName);
}
}
}
// This constructor is called indirectly by LINQ's query methods, just pass to base.
public ExcelQueryable(IQueryProvider provider, Expression expression)
: base(provider, expression)
{ }
}
}