Skip to content

Commit ca74c4e

Browse files
committed
HomogenizedDictionaryIndex.cs
1 parent a9006a0 commit ca74c4e

9 files changed

Lines changed: 52 additions & 20 deletions

File tree

Simple.Data.Ado/DataReaderExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ private static IEnumerable<IEnumerable<IDictionary<string,object>>> ToMultipleDi
3535
private static IEnumerable<IDictionary<string,object>> ToDictionariesImpl(IDataReader reader)
3636
{
3737
var index = OptimizedDictionary.CreateIndex(reader.GetFieldNames().Select(n => n.Homogenize()));
38+
var values = new object[reader.FieldCount];
3839
while (reader.Read())
3940
{
40-
yield return reader.ToDictionary(index);
41+
reader.GetValues(values);
42+
yield return OptimizedDictionary.Create(index, values);
4143
}
4244
}
4345

Simple.Data.Ado/DataRecordExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Data;
4+
using Simple.Data.Extensions;
45

56
namespace Simple.Data.Ado
67
{
@@ -28,7 +29,7 @@ public static dynamic ToDynamicRecord(this IDataRecord dataRecord, OptimizedDict
2829

2930
public static Dictionary<string, object> ToDictionary(this IDataRecord dataRecord)
3031
{
31-
return dataRecord.GetFieldNames().ToDictionary(fieldName => fieldName, fieldName => dataRecord[fieldName]);
32+
return dataRecord.GetFieldNames().ToDictionary(fieldName => fieldName.Homogenize(), fieldName => dataRecord[fieldName]);
3233
}
3334

3435
public static IDictionary<string, object> ToDictionary(this IDataRecord dataRecord, OptimizedDictionaryIndex<string> index)
0 Bytes
Binary file not shown.

Simple.Data.SqlTest/ObservableDataReaderTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading;
77
using NUnit.Framework;
88
using Simple.Data.Ado;
9+
using Simple.Data.Extensions;
910

1011
namespace Simple.Data.SqlTest
1112
{
@@ -85,7 +86,7 @@ public void ToAsyncEnumerable_Should_Work_After_Pause()
8586
Thread.Sleep(100);
8687
foreach (var user in users)
8788
{
88-
Console.WriteLine(user["Id"]);
89+
Assert.IsTrue(user.ContainsKey("Id".Homogenize()));
8990
}
9091

9192
}

Simple.Data.SqlTest/app.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</configSections>
55
<connectionStrings>
66
<add name="Simple.Data.SqlTest.Properties.Settings.ConnectionString"
7-
connectionString="Data Source=.;Initial Catalog=SimpleTest;Integrated Security=True"
7+
connectionString="Data Source=.\SQLSERVER2008;Initial Catalog=SimpleTest;Integrated Security=True"
88
providerName="System.Data.SqlClient" />
99
</connectionStrings>
1010
</configuration>

Simple.Data.sln

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assemblies", "Assemblies",
2525
EndProject
2626
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple.Data.SqlTest", "Simple.Data.SqlTest\Simple.Data.SqlTest.csproj", "{EFA5B19B-D24F-497E-AB48-8588ABFD1D01}"
2727
EndProject
28-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple.Data.SqlCe35", "Simple.Data.SqlCe35\Simple.Data.SqlCe35.csproj", "{1EDAC58F-C0CC-42E3-AA3A-C4A0175B5273}"
29-
EndProject
3028
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{182AEEFE-9B89-4264-BCED-91A00D1EF896}"
3129
EndProject
3230
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple.Data.Mocking", "Simple.Data.Mocking\Simple.Data.Mocking.csproj", "{292611F6-BBBD-492D-891C-0D9FB4BF5433}"
3331
EndProject
3432
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple.Data.Mocking.Test", "Simple.Data.Mocking.Test\Simple.Data.Mocking.Test.csproj", "{D4FE470E-4B01-4120-B809-F426A0179191}"
3533
EndProject
36-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple.Data.SqlCe35Test", "Simple.Data.SqlCe35Test\Simple.Data.SqlCe35Test.csproj", "{29BBCAE1-DF13-40A0-A412-F2F87F4E9351}"
37-
EndProject
3834
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple.Data.SqlServer", "Simple.Data.SqlServer\Simple.Data.SqlServer.csproj", "{E24F1C0F-3DCD-4BE5-9A6E-78EF6CB392A1}"
3935
EndProject
4036
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple.Data.AdapterApi", "Simple.Data.AdapterApi\Simple.Data.AdapterApi.csproj", "{67ACEAD5-B457-4B52-9C55-611A61A73B56}"
@@ -70,10 +66,6 @@ Global
7066
{EFA5B19B-D24F-497E-AB48-8588ABFD1D01}.Debug|Any CPU.Build.0 = Debug|Any CPU
7167
{EFA5B19B-D24F-497E-AB48-8588ABFD1D01}.Release|Any CPU.ActiveCfg = Release|Any CPU
7268
{EFA5B19B-D24F-497E-AB48-8588ABFD1D01}.Release|Any CPU.Build.0 = Release|Any CPU
73-
{1EDAC58F-C0CC-42E3-AA3A-C4A0175B5273}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
74-
{1EDAC58F-C0CC-42E3-AA3A-C4A0175B5273}.Debug|Any CPU.Build.0 = Debug|Any CPU
75-
{1EDAC58F-C0CC-42E3-AA3A-C4A0175B5273}.Release|Any CPU.ActiveCfg = Release|Any CPU
76-
{1EDAC58F-C0CC-42E3-AA3A-C4A0175B5273}.Release|Any CPU.Build.0 = Release|Any CPU
7769
{292611F6-BBBD-492D-891C-0D9FB4BF5433}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7870
{292611F6-BBBD-492D-891C-0D9FB4BF5433}.Debug|Any CPU.Build.0 = Debug|Any CPU
7971
{292611F6-BBBD-492D-891C-0D9FB4BF5433}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -82,10 +74,6 @@ Global
8274
{D4FE470E-4B01-4120-B809-F426A0179191}.Debug|Any CPU.Build.0 = Debug|Any CPU
8375
{D4FE470E-4B01-4120-B809-F426A0179191}.Release|Any CPU.ActiveCfg = Release|Any CPU
8476
{D4FE470E-4B01-4120-B809-F426A0179191}.Release|Any CPU.Build.0 = Release|Any CPU
85-
{29BBCAE1-DF13-40A0-A412-F2F87F4E9351}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
86-
{29BBCAE1-DF13-40A0-A412-F2F87F4E9351}.Debug|Any CPU.Build.0 = Debug|Any CPU
87-
{29BBCAE1-DF13-40A0-A412-F2F87F4E9351}.Release|Any CPU.ActiveCfg = Release|Any CPU
88-
{29BBCAE1-DF13-40A0-A412-F2F87F4E9351}.Release|Any CPU.Build.0 = Release|Any CPU
8977
{E24F1C0F-3DCD-4BE5-9A6E-78EF6CB392A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
9078
{E24F1C0F-3DCD-4BE5-9A6E-78EF6CB392A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
9179
{E24F1C0F-3DCD-4BE5-9A6E-78EF6CB392A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -122,7 +110,6 @@ Global
122110
{EFA5B19B-D24F-497E-AB48-8588ABFD1D01} = {182AEEFE-9B89-4264-BCED-91A00D1EF896}
123111
{1D2908F9-A78B-4EE1-8DAA-D4DBF3937C58} = {182AEEFE-9B89-4264-BCED-91A00D1EF896}
124112
{D4FE470E-4B01-4120-B809-F426A0179191} = {182AEEFE-9B89-4264-BCED-91A00D1EF896}
125-
{29BBCAE1-DF13-40A0-A412-F2F87F4E9351} = {182AEEFE-9B89-4264-BCED-91A00D1EF896}
126113
{96C623FD-869E-4DCE-98A1-17075EE384F9} = {182AEEFE-9B89-4264-BCED-91A00D1EF896}
127114
{70536BA8-AF0D-46F3-B04C-45177F56B320} = {182AEEFE-9B89-4264-BCED-91A00D1EF896}
128115
{E9160373-8BD2-4D69-B88E-1D3B5BC0A6FB} = {182AEEFE-9B89-4264-BCED-91A00D1EF896}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Simple.Data.Extensions;
6+
7+
namespace Simple.Data
8+
{
9+
public class HomogenizedDictionaryIndex : OptimizedDictionaryIndex<string>
10+
{
11+
internal HomogenizedDictionaryIndex(IDictionary<string, int> index) : base(index)
12+
{
13+
}
14+
15+
public override bool ContainsKey(string key)
16+
{
17+
return base.ContainsKey(key.Homogenize());
18+
}
19+
20+
public override int this[string key]
21+
{
22+
get
23+
{
24+
return base[key.Homogenize()];
25+
}
26+
}
27+
28+
public override bool TryGetIndex(string key, out int index)
29+
{
30+
return base.TryGetIndex(key.Homogenize(), out index);
31+
}
32+
33+
public static HomogenizedDictionaryIndex CreateIndex(IEnumerable<string> keys)
34+
{
35+
var index = keys.Select((key, i) => new KeyValuePair<string, int>(key.Homogenize(), i)).ToDictionary(kvp => kvp.Key,
36+
kvp => kvp.Value);
37+
return new HomogenizedDictionaryIndex(index);
38+
}
39+
}
40+
}

Simple.Data/OptimizedDictionaryIndex.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal OptimizedDictionaryIndex(IDictionary<T,int> index)
1111
_index = new Dictionary<T, int>(index);
1212
}
1313

14-
public int this[T key]
14+
public virtual int this[T key]
1515
{
1616
get { return _index[key]; }
1717
}
@@ -21,12 +21,12 @@ public IEnumerable<T> GetKeys()
2121
return _index.Keys;
2222
}
2323

24-
public bool ContainsKey(T key)
24+
public virtual bool ContainsKey(T key)
2525
{
2626
return _index.ContainsKey(key);
2727
}
2828

29-
public bool TryGetIndex(T key, out int index)
29+
public virtual bool TryGetIndex(T key, out int index)
3030
{
3131
return _index.TryGetValue(key, out index);
3232
}

Simple.Data/Simple.Data.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Compile Include="ConcreteObject.cs" />
7070
<Compile Include="ConcreteTypeCreator.cs" />
7171
<Compile Include="Database.Open.cs" />
72+
<Compile Include="HomogenizedDictionaryIndex.cs" />
7273
<Compile Include="IRange.cs" />
7374
<Compile Include="OptimizedDictionary.cs" />
7475
<Compile Include="OptimizedDictionaryIndex.cs" />

0 commit comments

Comments
 (0)