Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added generic methods and updated C# version #10

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3856a72
feat: added new benchmarks for comparison to manual mapping
amyskippy Oct 2, 2024
ab4f927
feat: added AccessModifier property to the GenerateDataReaderMapper a…
amyskippy Oct 2, 2024
8dab451
feat: added method to get the access modifier value
amyskippy Oct 2, 2024
7d7e83b
feat: using the access modifier for SetPropertyByName and To<ClassNam…
amyskippy Oct 2, 2024
2386441
test: added tests for the new access modifer
amyskippy Oct 2, 2024
acee9ce
refactor: fixed typo
amyskippy Oct 2, 2024
a8b48bf
feat: updated to latest C# language
amyskippy Oct 2, 2024
7bb7ab3
fix: added null and type checking
amyskippy Oct 2, 2024
c0fcfe5
feat: updated to use string literals and generic methods
amyskippy Oct 2, 2024
4c5cae3
refactor: updated usages to use new syntax
amyskippy Oct 2, 2024
c0e4227
docs: added xmldoc statements for methods
amyskippy Oct 2, 2024
f1fe8e6
refactor: updated some syntax to use latest c# features
amyskippy Oct 2, 2024
72ca540
docs: added additional xmldoc statements for the generated code
amyskippy Oct 2, 2024
7ab1312
docs: updated readme with the call to the newer and older mapping method
amyskippy Oct 2, 2024
42b5809
docs: updated documentation with details of the new access modifier
amyskippy Oct 2, 2024
27590de
Merge pull request #1 from amyskippy/feature/additional-benchmarks
amyskippy Oct 4, 2024
0758da8
Merge pull request #2 from amyskippy/feature/access-modifier
amyskippy Oct 4, 2024
8d91fb3
Merge branch 'main' into feature/generic-extensions
amyskippy Oct 4, 2024
95aa1f3
refactor: removed the obsolete attribute
amyskippy Oct 6, 2024
20a1296
docs: updated the documentation
amyskippy Oct 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MapDataReader.Benchmarks/MapDataReader.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
30 changes: 25 additions & 5 deletions MapDataReader.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,30 @@ public void MapDatareader_ViaDapper()
}

[Benchmark]
public void MapDataReader_ViaMapaDataReader()
public void MapDataReader_ViaMapDataReader()
{
var dr = _dt.CreateDataReader();
var list = dr.ToTestClass();
var list = dr.To<TestClass>();
}

[Benchmark]
public void MapDataReader_ViaManualMap()
{
var dr = _dt.CreateDataReader();

var list = new List<TestClass>();
while (dr.Read())
{
list.Add(new TestClass
{
String1 = dr["String1"] as string,
String2 = dr["String2"] as string,
String3 = dr["String3"] as string,
Int = dr.GetInt32(3),
Int2 = dr.GetInt32(4),
IntNullable = dr["IntNullable"] as int?
});
}
}

static DataTable _dt;
Expand All @@ -93,14 +113,14 @@ public static void Setup()
}
}

[GenerateDataReaderMapper]
[GenerateDataReaderMapper(AccessModifier = "internal")]
public class TestClass
{
public string String1 { get; set; }
public string String2 { get; set; }
public string String3 { get; set; }
public string Int { get; set; }
public string Int2 { get; set; }
public int Int { get; set; }
public int Int2 { get; set; }
public int? IntNullable { get; set; }
}
}
2 changes: 1 addition & 1 deletion MapDataReader.Tests/MapDataReader.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
37 changes: 34 additions & 3 deletions MapDataReader.Tests/TestActualCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -147,7 +148,7 @@ public void TestStringAssign()
}

[TestMethod]
public void TestDatatReader()
public void TestDataReader()
{
//create datatable with test data
var dt = new DataTable();
Expand All @@ -165,7 +166,7 @@ public void TestDatatReader()
dt.Rows.Add(123, "ggg", true, 3213, 123, date, TimeSpan.FromSeconds(123), new byte[] { 3, 2, 1 });
dt.Rows.Add(3, "fgdk", false, 11123, 321, date, TimeSpan.FromSeconds(123), new byte[] { 5, 6, 7, 8 });

var list = dt.CreateDataReader().ToMyObject();
var list = dt.CreateDataReader().To<MyObject>();

Assert.IsTrue(list.Count == 2);

Expand Down Expand Up @@ -198,7 +199,7 @@ public void TestDatatReader()

dt2.Rows.Add(true, "alex", 123);

list = dt2.CreateDataReader().ToMyObject(); //should not throw exception
list = dt2.CreateDataReader().To<MyObject>(); //should not throw exception

Assert.IsTrue(list[0].Id == 123);
Assert.IsTrue(list[0].Name == "alex");
Expand Down Expand Up @@ -227,6 +228,24 @@ public void TestWrongProperty()
o.SetPropertyByName("Name", 123); //try to assign string prop to int
Assert.IsTrue(o.Name == null); //wrong type. should be null
}

[TestMethod]
public void TestInternalAccessModifier()
{
var type = typeof(TestClassInternalExtensions);
var method = type.GetMethod("To", BindingFlags.Static | BindingFlags.NonPublic);

Assert.IsNotNull(method, "Expected method 'To' to be 'internal'.");
}

[TestMethod]
public void TestInternalAccessModifierNamed()
{
var type = typeof(TestClassInternalNamedExtensions);
var method = type.GetMethod("To", BindingFlags.Static | BindingFlags.NonPublic);

Assert.IsNotNull(method, "Expected method 'To' to be 'internal'.");
}
}

public class BaseClass
Expand All @@ -239,5 +258,17 @@ public class ChildClass : BaseClass
{
public string Name { get; set; }
}

[GenerateDataReaderMapper("internal")]
internal class TestClassInternal
{
public int Id { get; set; }
}

[GenerateDataReaderMapper(AccessModifier = "internal")]
internal class TestClassInternalNamed
{
public int Id { get; set; }
}
}

23 changes: 23 additions & 0 deletions MapDataReader.Tests/TestGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ public class MyClass
public decimal Price {get;set;}
}
}
";
var src = GetAndCheckOutputSource(userSource);
}

[TestMethod]
public void TestAccessModifier()
{
string userSource = @"
using MapDataReader;

namespace MyCode
{
[GenerateDataReaderMapper(AccessModifier = ""internal"")]
public class MyClass
{
public string Name {get;set;}
public int Size {get;set;}
public bool Enabled {get;set;}
public System.DateTime Created {get;set;}
public System.DateTimeOffset Offset {get;set;}
public decimal Price {get;set;}
}
}
";
var src = GetAndCheckOutputSource(userSource);
}
Expand Down
1 change: 1 addition & 0 deletions MapDataReader/MapDataReader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageTags>aot;source-generator</PackageTags>
<Description>Super fast mapping of DataReader to custom objects</Description>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading