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

loresoft / FluentCommand / 8850661434

26 Apr 2024 03:30PM UTC coverage: 54.48% (+2.6%) from 51.881%
8850661434

push

github

pwelter34
update debug settings

1152 of 2717 branches covered (42.4%)

Branch coverage included in aggregate %.

3682 of 6156 relevant lines covered (59.81%)

701.76 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
    [Obsolete("Use generated data reader factory")]
20
    public static TEntity EntityFactory<TEntity>(this IDataReader reader)
21
        where TEntity : class, new()
22
    {
23
        var entityAccessor = TypeAccessor.GetAccessor<TEntity>();
×
24
        var entity = new TEntity();
×
25

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

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

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

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

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

42
        return entity;
×
43
    }
44

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

55
        for (int i = 0; i < reader.FieldCount; i++)
15,120✔
56
            dictionary.Add(reader.GetName(i), reader[i]);
7,182✔
57

58
        return expando;
378✔
59
    }
60
}
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