• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / FluentCommand / 5874771988

16 Aug 2023 04:44AM UTC coverage: 43.028% (+2.5%) from 40.495%
5874771988

push

github

web-flow
Merge pull request #277 from loresoft/feature/method-injectors

Feature/method injectors

765 of 2171 branches covered (35.24%)

Branch coverage included in aggregate %.

126 of 126 new or added lines in 6 files covered. (100.0%)

2361 of 5094 relevant lines covered (46.35%)

119.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.43
/src/FluentCommand/DataReaderExtensions.cs
1
using System.Data;
2
using System.Dynamic;
3

4
using FluentCommand.Reflection;
5

6
namespace FluentCommand;
7

8
/// <summary>
9
/// Extension methods for <see cref="IDataReader"/>
10
/// </summary>
11
public static class DataReaderExtensions
12
{
13
    /// <summary>
14
    /// A factory for creating TEntity objects from the current row in the <see cref="IDataReader" />.
15
    /// </summary>
16
    /// <typeparam name="TEntity">The type of the entity.</typeparam>
17
    /// <param name="reader">The open <see cref="IDataReader" /> to get the object from.</param>
18
    /// <returns>A TEntity object having property names set that match the field names in the <see cref="IDataReader" />.</returns>
19
    public static TEntity EntityFactory<TEntity>(this IDataReader reader)
20
        where TEntity : class, new()
21
    {
22
        var entityAccessor = TypeAccessor.GetAccessor<TEntity>();
×
23
        var entity = new TEntity();
×
24

25
        for (int i = 0; i < reader.FieldCount; i++)
×
26
        {
27
            if (reader.IsDBNull(i))
×
28
                continue;
29

30
            var name = reader.GetName(i);
×
31

32
            var memberAccessor = entityAccessor.FindColumn(name);
×
33
            if (memberAccessor == null)
×
34
                continue;
35

36
            var value = reader.GetValue(i);
×
37

38
            memberAccessor.SetValue(entity, value);
×
39
        }
40

41
        return entity;
×
42
    }
43

44
    /// <summary>
45
    /// A factory for creating dynamic objects from the current row in the <see cref="IDataReader" />.
46
    /// </summary>
47
    /// <param name="reader">The open <see cref="IDataReader" /> to get the object from.</param>
48
    /// <returns>A dynamic object having property names set that match the field names in the <see cref="IDataReader" />.</returns>
49
    public static dynamic DynamicFactory(IDataReader reader)
50
    {
51
        dynamic expando = new ExpandoObject();
150✔
52
        var dictionary = expando as IDictionary<string, object>;
150✔
53

54
        for (int i = 0; i < reader.FieldCount; i++)
5,600✔
55
            dictionary.Add(reader.GetName(i), reader[i]);
2,650✔
56

57
        return expando;
150✔
58
    }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc