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

loresoft / EntityChange / 13417967502

19 Feb 2025 04:51PM UTC coverage: 45.43% (+5.7%) from 39.697%
13417967502

push

github

pwelter34
fix failing test

287 of 726 branches covered (39.53%)

Branch coverage included in aggregate %.

563 of 1145 relevant lines covered (49.17%)

73.33 hits per line

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

51.22
/src/EntityChange/Reflection/PropertyAccessor.cs
1
#nullable disable
2

3
using System.Reflection;
4

5
namespace EntityChange.Reflection;
6

7
/// <summary>
8
/// An accessor class for <see cref="PropertyInfo"/>.
9
/// </summary>
10
public class PropertyAccessor : MemberAccessor
11
{
12
    private readonly Lazy<Func<object, object>> _getter;
13
    private readonly Lazy<Action<object, object>> _setter;
14

15
    /// <summary>
16
    /// Initializes a new instance of the <see cref="PropertyAccessor"/> class.
17
    /// </summary>
18
    /// <param name="propertyInfo">The <see cref="PropertyInfo"/> instance to use for this accessor.</param>
19
    public PropertyAccessor(PropertyInfo propertyInfo) : base(propertyInfo)
39✔
20
    {
21
        if (propertyInfo == null)
39!
22
            throw new ArgumentNullException(nameof(propertyInfo));
×
23

24
        Name = propertyInfo.Name;
39✔
25
        MemberType = propertyInfo.PropertyType;
39✔
26

27
        HasGetter = propertyInfo.CanRead;
39✔
28
        _getter = new Lazy<Func<object, object>>(() => ExpressionFactory.CreateGet(propertyInfo));
78✔
29

30
        HasSetter = propertyInfo.CanWrite;
39✔
31
        _setter = new Lazy<Action<object, object>>(() => ExpressionFactory.CreateSet(propertyInfo));
39✔
32
    }
39✔
33

34

35
    /// <summary>
36
    /// Gets the type of the member.
37
    /// </summary>
38
    /// <value>The type of the member.</value>
39
    public override Type MemberType { get; }
297✔
40

41
    /// <summary>
42
    /// Gets the name of the member.
43
    /// </summary>
44
    /// <value>The name of the member.</value>
45
    public override string Name { get; }
3,473✔
46

47
    /// <summary>
48
    /// Gets a value indicating whether this member has getter.
49
    /// </summary>
50
    /// <value><c>true</c> if this member has getter; otherwise, <c>false</c>.</value>
51
    public override bool HasGetter { get; }
885✔
52

53
    /// <summary>
54
    /// Gets a value indicating whether this member has setter.
55
    /// </summary>
56
    /// <value><c>true</c> if this member has setter; otherwise, <c>false</c>.</value>
57
    public override bool HasSetter { get; }
291✔
58

59

60
    /// <summary>
61
    /// Returns the value of the member.
62
    /// </summary>
63
    /// <param name="instance">The object whose member value will be returned.</param>
64
    /// <returns>
65
    /// The member value for the instance parameter.
66
    /// </returns>
67
    public override object GetValue(object instance)
68
    {
69
        if (_getter == null || !HasGetter)
594!
70
            throw new InvalidOperationException($"Property '{Name}' does not have a getter.");
×
71

72
        var get = _getter.Value;
594✔
73
        if (get == null)
594!
74
            throw new InvalidOperationException($"Property '{Name}' does not have a getter.");
×
75

76
        return get(instance);
594✔
77
    }
78

79
    /// <summary>
80
    /// Sets the value of the member.
81
    /// </summary>
82
    /// <param name="instance">The object whose member value will be set.</param>
83
    /// <param name="value">The new value for this member.</param>
84
    public override void SetValue(object instance, object value)
85
    {
86
        if (_setter == null || !HasSetter)
×
87
            throw new InvalidOperationException($"Property '{Name}' does not have a setter.");
×
88

89
        var set = _setter.Value;
×
90
        if (set == null)
×
91
            throw new InvalidOperationException($"Property '{Name}' does not have a setter.");
×
92

93
        set(instance, value);
×
94
    }
×
95
}
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