diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index 27d679a..e04768b 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
- dotnet-version: 7.0.x
+ dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
diff --git a/Directory.Packages.props b/Directory.Packages.props
index c0dbd32..2e1e762 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -3,11 +3,11 @@
true
-
-
-
+
+
+
-
-
+
+
\ No newline at end of file
diff --git a/EnumerableDataReaderAdapter.sln b/EnumerableDataReaderAdapter.sln
index 97800c5..f86d03f 100644
--- a/EnumerableDataReaderAdapter.sln
+++ b/EnumerableDataReaderAdapter.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.28010.2019
+# Visual Studio Version 17
+VisualStudioVersion = 17.8.34112.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{19031506-5145-42F6-9AB6-AE7C1E4ACF80}"
EndProject
@@ -15,6 +15,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnumerableDataReaderAdapter
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnumerableDataReaderAdapter.Benchmarks", "benchmarks\EnumerableDataReaderAdapter.Benchmarks\EnumerableDataReaderAdapter.Benchmarks.csproj", "{80F9D7ED-93C8-4805-89A4-3B581AB00F34}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C5F1FAE8-92F2-4FF8-B6C8-A2AFE3A67F8B}"
+ ProjectSection(SolutionItems) = preProject
+ .gitattributes = .gitattributes
+ .gitignore = .gitignore
+ Directory.Build.props = Directory.Build.props
+ Directory.Packages.props = Directory.Packages.props
+ LICENSE = LICENSE
+ nuget.config = nuget.config
+ README.md = README.md
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
diff --git a/benchmarks/EnumerableDataReaderAdapter.Benchmarks/EnumerableDataReaderAdapter.Benchmarks.csproj b/benchmarks/EnumerableDataReaderAdapter.Benchmarks/EnumerableDataReaderAdapter.Benchmarks.csproj
index 4475262..e8875f6 100644
--- a/benchmarks/EnumerableDataReaderAdapter.Benchmarks/EnumerableDataReaderAdapter.Benchmarks.csproj
+++ b/benchmarks/EnumerableDataReaderAdapter.Benchmarks/EnumerableDataReaderAdapter.Benchmarks.csproj
@@ -2,7 +2,7 @@
Exe
- net6.0;net7.0
+ net6.0;net7.0;net8.0
diff --git a/benchmarks/EnumerableDataReaderAdapter.Benchmarks/Program.cs b/benchmarks/EnumerableDataReaderAdapter.Benchmarks/Program.cs
index d8433cd..3193798 100644
--- a/benchmarks/EnumerableDataReaderAdapter.Benchmarks/Program.cs
+++ b/benchmarks/EnumerableDataReaderAdapter.Benchmarks/Program.cs
@@ -25,12 +25,13 @@ public DataStructure(
[SimpleJob(BenchmarkDotNet.Jobs.RuntimeMoniker.Net60)]
[SimpleJob(BenchmarkDotNet.Jobs.RuntimeMoniker.Net70)]
+ [SimpleJob(BenchmarkDotNet.Jobs.RuntimeMoniker.Net80)]
[RPlotExporter, RankColumn]
[MemoryDiagnoser]
public class EnumerableDataReaderBenchmark
{
- private DataStructure[] data = default!;
- private object[] buffer = default!;
+ private DataStructure[] _data = default!;
+ private object[] _buffer = default!;
static readonly ColumnMappings _mappingDelegates = new ColumnMappings()
.Add(nameof(DataStructure.StringField), typeof(string), p => p.StringField)
@@ -48,137 +49,117 @@ public class EnumerableDataReaderBenchmark
[GlobalSetup]
public void Setup()
{
- data = Enumerable.Range(1, N)
+ _data = Enumerable.Range(1, N)
.Select(i => new DataStructure($"{i}", i, (i % 2) == 0 ? (int?)null : i))
.ToArray();
- buffer = new object[3];
+ _buffer = new object[3];
}
[Benchmark(Baseline = true)]
public void DefaultMapping_ByColumnIndex()
{
- using (var reader = data.ToDataReader())
- {
- while (reader.Read()) GetDataByColumnIndex(reader);
- }
+ using var reader = _data.ToDataReader();
+ while (reader.Read()) GetDataByColumnIndex(reader);
}
[Benchmark]
public void MappingExpressions_ByColumnIndex()
{
- using (var reader = data.ToDataReader(
+ using var reader = _data.ToDataReader(
mapping => mapping
.Add(p => p.StringField)
.Add(p => p.IntField)
.Add(p => p.NullableIntField)
- ))
- {
- while (reader.Read()) GetDataByColumnIndex(reader);
- }
+ );
+ while (reader.Read()) GetDataByColumnIndex(reader);
}
[Benchmark]
public void MappingExpressions_ByColumnIndex_CachedMapping()
{
- using (var reader = data.ToDataReader(_mappingExpressions))
- {
- while (reader.Read()) GetDataByColumnIndex(reader);
- }
+ using var reader = _data.ToDataReader(_mappingExpressions);
+ while (reader.Read()) GetDataByColumnIndex(reader);
}
[Benchmark]
public void MappingDelegates_ByColumnIndex()
{
- using (var reader = data.ToDataReader(
+ using var reader = _data.ToDataReader(
mapping => mapping
.Add(nameof(DataStructure.StringField), typeof(string), p => p.StringField)
.Add(nameof(DataStructure.IntField), typeof(int), p => p.IntField)
.Add(nameof(DataStructure.NullableIntField), typeof(int?), p => p.NullableIntField)
- ))
- {
- while (reader.Read()) GetDataByColumnIndex(reader);
- }
+ );
+ while (reader.Read()) GetDataByColumnIndex(reader);
}
[Benchmark]
public void MappingDelegates_ByColumnIndex_CachedMapping()
{
- using (var reader = data.ToDataReader(_mappingDelegates))
- {
- while (reader.Read()) GetDataByColumnIndex(reader);
- }
+ using var reader = _data.ToDataReader(_mappingDelegates);
+ while (reader.Read()) GetDataByColumnIndex(reader);
}
[Benchmark()]
public void DefaultMapping_ByColumnName()
{
- using (var reader = data.ToDataReader())
- {
- while (reader.Read()) GetDataByColumnName(reader);
- }
+ using var reader = _data.ToDataReader();
+ while (reader.Read()) GetDataByColumnName(reader);
}
[Benchmark]
public void MappingExpressions_ByColumnName()
{
- using (var reader = data.ToDataReader(
+ using var reader = _data.ToDataReader(
mapping => mapping
.Add(p => p.StringField)
.Add(p => p.IntField)
.Add(p => p.NullableIntField)
- ))
- {
- while (reader.Read()) GetDataByColumnName(reader);
- }
+ );
+ while (reader.Read()) GetDataByColumnName(reader);
}
[Benchmark]
public void MappingExpressions_ByColumnName_CachedMapping()
{
- using (var reader = data.ToDataReader(_mappingExpressions))
- {
- while (reader.Read()) GetDataByColumnName(reader);
- }
+ using var reader = _data.ToDataReader(_mappingExpressions);
+ while (reader.Read()) GetDataByColumnName(reader);
}
[Benchmark]
public void MappingDelegates_ByColumnName()
{
- using (var reader = data.ToDataReader(
+ using var reader = _data.ToDataReader(
mapping => mapping
.Add(nameof(DataStructure.StringField), typeof(string), p => p.StringField)
.Add(nameof(DataStructure.IntField), typeof(int), p => p.IntField)
.Add(nameof(DataStructure.NullableIntField), typeof(int?), p => p.NullableIntField)
- ))
- {
- while (reader.Read()) GetDataByColumnName(reader);
- }
+ );
+ while (reader.Read()) GetDataByColumnName(reader);
}
[Benchmark]
public void MappingDelegates_ByColumnName_CachedMapping()
{
- using (var reader = data.ToDataReader(_mappingDelegates))
- {
- while (reader.Read()) GetDataByColumnName(reader);
- }
+ using var reader = _data.ToDataReader(_mappingDelegates);
+ while (reader.Read()) GetDataByColumnName(reader);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void GetDataByColumnIndex(IDataReader reader)
{
- buffer[0] = reader[0];
- buffer[1] = reader[1];
- buffer[2] = reader[2];
+ _buffer[0] = reader[0];
+ _buffer[1] = reader[1];
+ _buffer[2] = reader[2];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void GetDataByColumnName(IDataReader reader)
{
- buffer[0] = reader[nameof(DataStructure.StringField)];
- buffer[1] = reader[nameof(DataStructure.IntField)];
- buffer[2] = reader[nameof(DataStructure.NullableIntField)];
+ _buffer[0] = reader[nameof(DataStructure.StringField)];
+ _buffer[1] = reader[nameof(DataStructure.IntField)];
+ _buffer[2] = reader[nameof(DataStructure.NullableIntField)];
}
}
diff --git a/src/EnumerableDataReaderAdapter/ColumnMapping.cs b/src/EnumerableDataReaderAdapter/ColumnMapping.cs
index 14ff773..194edbe 100644
--- a/src/EnumerableDataReaderAdapter/ColumnMapping.cs
+++ b/src/EnumerableDataReaderAdapter/ColumnMapping.cs
@@ -32,7 +32,7 @@ static ColumnMappings()
}).ToArray();
}
- private List<(string ColumnName, Type ColumnType, Func ValueGetter)> _mappings = new();
+ private readonly List<(string ColumnName, Type ColumnType, Func ValueGetter)> _mappings = new();
public ColumnMappings Add(string columnName, Type type, Func valueGetter)
{
@@ -68,15 +68,10 @@ public ColumnMappings Add(Expression> propertyExpression)
}
var body = propertyExpression.Body;
- var memberExpression = body is UnaryExpression ue
+ var memberExpression = (body is UnaryExpression ue
? ue.Operand as MemberExpression
- : body as MemberExpression;
-
- if (memberExpression is null)
- {
- throw new ArgumentException("Expected a member expression.", nameof(propertyExpression));
- }
-
+ : body as MemberExpression)
+ ?? throw new ArgumentException("Expected a member expression.", nameof(propertyExpression));
_mappings.Add(
(ColumnName: memberExpression.Member.Name,
ColumnType: memberExpression.Type,
diff --git a/src/EnumerableDataReaderAdapter/EnumerableDataReaderAdapter.csproj b/src/EnumerableDataReaderAdapter/EnumerableDataReaderAdapter.csproj
index 5d83bbd..0349553 100644
--- a/src/EnumerableDataReaderAdapter/EnumerableDataReaderAdapter.csproj
+++ b/src/EnumerableDataReaderAdapter/EnumerableDataReaderAdapter.csproj
@@ -1,7 +1,7 @@
- net6.0;net7.0
+ net6.0;net7.0;net8.0
diff --git a/src/EnumerableDataReaderAdapter/EnumerableExtensions.cs b/src/EnumerableDataReaderAdapter/EnumerableExtensions.cs
index cc98eb5..47cbd13 100644
--- a/src/EnumerableDataReaderAdapter/EnumerableExtensions.cs
+++ b/src/EnumerableDataReaderAdapter/EnumerableExtensions.cs
@@ -39,7 +39,7 @@ private sealed class EnumerableReaderAdapter : DbDataReader
private bool _isClosed = false;
private IEnumerator _enumerator;
private T _current = default!;
- private Lazy> _columnLookup;
+ private readonly Lazy> _columnLookup;
private long _rowCount = 0;
public EnumerableReaderAdapter(
@@ -68,7 +68,7 @@ public override IEnumerator GetEnumerator()
public override DataTable GetSchemaTable()
{
- DataTable table = new DataTable("SchemaTable");
+ DataTable table = new("SchemaTable");
table.Columns.Add(SchemaTableColumn.ColumnName, typeof(string));
table.Columns.Add(SchemaTableColumn.ColumnOrdinal, typeof(int));
table.Columns.Add(SchemaTableColumn.ColumnSize, typeof(int));
@@ -155,9 +155,9 @@ public override int GetValues(object?[] values)
public override Type GetFieldType(int i) => null!;
public override bool GetBoolean(int i) => (bool)GetValue(i);
public override byte GetByte(int i) => (byte)GetValue(i);
- public override long GetBytes(int i, long fieldOffset, byte[]? buffer, int bufferoffset, int length) => throw new NotSupportedException();
+ public override long GetBytes(int i, long fieldOffset, byte[]? buffer, int bufferOffset, int length) => throw new NotSupportedException();
public override char GetChar(int i) => (char)GetValue(i);
- public override long GetChars(int i, long fieldoffset, char[]? buffer, int bufferoffset, int length) => throw new NotSupportedException();
+ public override long GetChars(int i, long fieldOffset, char[]? buffer, int bufferOffset, int length) => throw new NotSupportedException();
public override Guid GetGuid(int i) => (Guid)GetValue(i);
public override short GetInt16(int i) => (short)GetValue(i);
public override int GetInt32(int i) => (int)GetValue(i);
diff --git a/test/EnumerableDataReaderAdapter.Tests/EnumerableDataReaderAdapter.Tests.csproj b/test/EnumerableDataReaderAdapter.Tests/EnumerableDataReaderAdapter.Tests.csproj
index cb3b329..e469396 100644
--- a/test/EnumerableDataReaderAdapter.Tests/EnumerableDataReaderAdapter.Tests.csproj
+++ b/test/EnumerableDataReaderAdapter.Tests/EnumerableDataReaderAdapter.Tests.csproj
@@ -1,7 +1,7 @@
- net6.0;net7.0
+ net6.0;net7.0;net8.0
false