forked from ThatRendle/Simple.Data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColumnCollection.cs
More file actions
46 lines (40 loc) · 1.53 KB
/
ColumnCollection.cs
File metadata and controls
46 lines (40 loc) · 1.53 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
45
46
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Simple.Data.Extensions;
namespace Simple.Data.Ado.Schema
{
class ColumnCollection : Collection<Column>
{
public ColumnCollection()
{
}
public ColumnCollection(IEnumerable<Column> columns) : base(columns.ToList())
{
}
/// <summary>
/// Finds the column with a name most closely matching the specified column name.
/// This method will try an exact match first, then a case-insensitve search, then a pluralized or singular version.
/// </summary>
/// <param name="columnName">Name of the column.</param>
/// <returns>A <see cref="Column"/> if a match is found; otherwise, <c>null</c>.</returns>
public Column Find(string columnName)
{
var column = FindColumnWithName(columnName);
if (column == null) throw new UnresolvableObjectException(columnName, string.Format("Column '{0}' not found.", columnName));
return column;
}
public bool Contains(string columnName)
{
return FindColumnWithName(columnName) != null;
}
private Column FindColumnWithName(string columnName)
{
columnName = columnName.Homogenize();
return this
.Where(c => c.HomogenizedName.Equals(columnName))
.SingleOrDefault();
}
}
}