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

loresoft / FluentCommand / 23278216331

19 Mar 2026 03:19AM UTC coverage: 57.398% (+0.7%) from 56.658%
23278216331

push

github

pwelter34
Enable nullable and improve source generators

1403 of 3069 branches covered (45.72%)

Branch coverage included in aggregate %.

527 of 907 new or added lines in 58 files covered. (58.1%)

22 existing lines in 10 files now uncovered.

4288 of 6846 relevant lines covered (62.64%)

330.58 hits per line

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

51.35
/src/FluentCommand/Reflection/PropertyAccessor.cs
1
using System.Reflection;
2

3
namespace FluentCommand.Reflection;
4

5
/// <summary>
6
/// Provides an accessor for <see cref="PropertyInfo"/>, enabling efficient dynamic get and set operations
7
/// on properties using compiled delegates. Inherits from <see cref="MemberAccessor"/> to provide
8
/// reflection-based access and metadata retrieval for properties.
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 using the specified <see cref="PropertyInfo"/>.
17
    /// </summary>
18
    /// <param name="propertyInfo">The <see cref="PropertyInfo"/> instance to use for this accessor.</param>
19
    /// <exception cref="ArgumentNullException">Thrown if <paramref name="propertyInfo"/> is <c>null</c>.</exception>
20
    public PropertyAccessor(PropertyInfo propertyInfo) : base(propertyInfo)
12✔
21
    {
22
        if (propertyInfo == null)
12!
23
            throw new ArgumentNullException(nameof(propertyInfo));
×
24

25
        Name = propertyInfo.Name;
12✔
26
        MemberType = propertyInfo.PropertyType;
12✔
27

28
        HasGetter = propertyInfo.CanRead;
12✔
29
        _getter = new Lazy<Func<object, object?>?>(() => ExpressionFactory.CreateGet(propertyInfo));
16✔
30

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

35
    /// <summary>
36
    /// Gets the <see cref="Type"/> of the property.
37
    /// </summary>
38
    /// <value>The <see cref="Type"/> representing the property's data type.</value>
39
    public override Type MemberType { get; }
16✔
40

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

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

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

59
    /// <summary>
60
    /// Gets the value of the property for the specified object instance.
61
    /// </summary>
62
    /// <param name="instance">The object whose property value will be returned.</param>
63
    /// <returns>The value of the property for the given <paramref name="instance"/>.</returns>
64
    /// <exception cref="InvalidOperationException">Thrown if the property does not have a getter.</exception>
65
    public override object? GetValue(object instance)
66
    {
67
        if (!HasGetter)
20!
68
            throw new InvalidOperationException($"Property '{Name}' does not have a getter.");
×
69

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

74
        return get(instance);
20✔
75
    }
76

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

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

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