Skip to content

Commit

Permalink
Merge pull request #29 from jholovacs/master
Browse files Browse the repository at this point in the history
Extracted IDatabase for mocking, added the ability to set case sensit…
  • Loading branch information
tmenier authored Aug 12, 2016
2 parents 5f20d95 + 09ef3a6 commit 2505dd3
Show file tree
Hide file tree
Showing 8 changed files with 3,343 additions and 977 deletions.
2,319 changes: 1,749 additions & 570 deletions AsyncPoco/AsyncPoco.cs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions AsyncPoco/AsyncPoco.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Compile Include="DatabaseTypes\SqlServerDatabaseType.cs" />
<Compile Include="DatabaseTypes\SqlServerCEDatabaseType.cs" />
<Compile Include="DatabaseTypes\MySqlDatabaseType.cs" />
<Compile Include="IDatabase.cs" />
<Compile Include="Utilities\AutoSelectHelper.cs" />
<Compile Include="Utilities\PagingHelper.cs" />
<Compile Include="Utilities\ParametersHelper.cs" />
Expand Down
4 changes: 3 additions & 1 deletion AsyncPoco/Core/MultiPocoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace AsyncPoco.Internal
{
class MultiPocoFactory
{
public static IEqualityComparer<string> FieldNameComparer { get; set; } = StringComparer.InvariantCultureIgnoreCase;

// Instance data used by the Multipoco factory delegate - essentially a list of the nested poco factories to call
List<Delegate> _delegates;
public Delegate GetItem(int index) { return _delegates[index]; }
Expand Down Expand Up @@ -75,7 +77,7 @@ static Delegate FindSplitPoint(Type typeThis, Type typeNext, string ConnectionSt

// Find split point
int firstColumn = pos;
var usedColumns = new Dictionary<string, bool>();
var usedColumns = new Dictionary<string, bool>(FieldNameComparer);
for (; pos < r.FieldCount; pos++)
{
// Split if field name has already been used, or if the field doesn't exist in current poco but does in the next
Expand Down
9 changes: 5 additions & 4 deletions AsyncPoco/Core/PocoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace AsyncPoco.Internal
{
class PocoData
{
public static IEqualityComparer<string> ColumnComparer { get;set;}=StringComparer.InvariantCultureIgnoreCase;

public static PocoData ForObject(object o, string primaryKeyName)
{
var t = o.GetType();
Expand All @@ -22,7 +24,7 @@ public static PocoData ForObject(object o, string primaryKeyName)
{
var pd = new PocoData();
pd.TableInfo = new TableInfo();
pd.Columns = new Dictionary<string, PocoColumn>(StringComparer.OrdinalIgnoreCase);
pd.Columns = new Dictionary<string, PocoColumn>(ColumnComparer);
pd.Columns.Add(primaryKeyName, new ExpandoColumn() { ColumnName = primaryKeyName });
pd.TableInfo.PrimaryKey = primaryKeyName;
pd.TableInfo.AutoIncrement = true;
Expand Down Expand Up @@ -63,7 +65,7 @@ public PocoData(Type t)
TableInfo = mapper.GetTableInfo(t);

// Work out bound properties
Columns = new Dictionary<string, PocoColumn>(StringComparer.OrdinalIgnoreCase);
Columns = new Dictionary<string, PocoColumn>(ColumnComparer);
foreach (var pi in t.GetProperties())
{
ColumnInfo ci = mapper.GetColumnInfo(pi);
Expand Down Expand Up @@ -116,7 +118,6 @@ public Delegate GetFactory(string sql, string connString, int firstColumn, int c
#if !PETAPOCO_NO_DYNAMIC
if (type == typeof(object))
{
// var poco=new T()
il.Emit(OpCodes.Newobj, typeof(System.Dynamic.ExpandoObject).GetConstructor(Type.EmptyTypes)); // obj

MethodInfo fnAdd = typeof(IDictionary<string, object>).GetMethod("Add");
Expand Down Expand Up @@ -251,7 +252,7 @@ public Delegate GetFactory(string sql, string connString, int firstColumn, int c
{
il.Emit(OpCodes.Newobj, dstType.GetConstructor(new Type[] { Nullable.GetUnderlyingType(dstType) }));
}

il.Emit(OpCodes.Callvirt, pc.PropertyInfo.GetSetMethod(true)); // poco
Handled = true;
}
Expand Down
Loading

0 comments on commit 2505dd3

Please # to comment.