Skip to content

Commit 79f7de2

Browse files
committed
docs: updated the documentation
1 parent 51a2a9e commit 79f7de2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Diff for: README.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,22 @@ public class MyClass
3636

3737
var dataReader = new SqlCommand("SELECT * FROM MyTable", connection).ExecuteReader();
3838

39-
List<MyClass> results = dataReader.To<MyClass>();
39+
List<MyClass> results = dataReader.To<MyClass>(); // Generic method
40+
41+
// or
42+
43+
List<MyClass> results = dataReader.ToMyClass(); // Direct method
4044
```
4145

4246
Some notes for the above
4347

44-
* The `ToMyClass()` method above - is an `IDataReader` extension method generated at compile time. You can even "go to definition" in Visual Studio and examine its code.
45-
* The naming convention is `ToCLASSNAME()` we can't use generics here, since `<T>` is not part of method signatures in C# (considered in later versions of C#). If you find a prettier way - please contribute!
46-
* Maps properies with public setters only.
48+
* The `To<MyClass>()` method above - is an `IDataReader` extension method generated at compile time.
49+
* The naming convention is `To<T>()` where `T` is your class name marked with `[GenerateDataReaderMapper]`, e.g. `MyClass`.
50+
* Thanks to [@5andr0](https://github.com/5andr0) for the suggestion of how to add the generic version of this method.
51+
* The `ToMyClass()` method is functionally identical to the `To<MyClass>()` method but maintained for backwards compatability.
52+
* The naming convention is `ToCLASSNAME()`
53+
* You can even "go to definition" in Visual Studio and examine the code for either of these two methods.
54+
* Maps properties with public setters only.
4755
* The datareader is being closed after mapping, so don't reuse it.
4856
* Supports `enum` properties based on `int` and other implicit casting (sometimes a DataReader may decide to return `byte` for small integer database value, and it maps to `int` perfectly via some unboxing magic)
4957
* Properly maps `DBNull` to `null`.
@@ -85,10 +93,10 @@ If you're already using the awesome [Dapper ORM](https://github.com/DapperLib/Da
8593
public static List<T> Query<T>(this SqlConnection cn, string sql, object parameters = null)
8694
{
8795
if (typeof(T) == typeof(MyClass)) //our own class that we marked with attribute?
88-
return cn.ExecuteReader(sql, parameters).ToMyClass() as List<T>; //use MapDataReader
96+
return cn.ExecuteReader(sql, parameters).To<MyClass>() as List<T>; //use MapDataReader
8997
9098
if (typeof(T) == typeof(AnotherClass)) //another class we have enabled?
91-
return cn.ExecuteReader(sql, parameters).ToAnotherClass() as List<T>; //again
99+
return cn.ExecuteReader(sql, parameters).To<AnotherClass>() as List<T>; //again
92100
93101
//fallback to Dapper by default
94102
return SqlMapper.Query<T>(cn, sql, parameters).AsList();

0 commit comments

Comments
 (0)