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

loresoft / FluentCommand / 26594173245

28 May 2026 06:28PM UTC coverage: 55.553% (+0.7%) from 54.902%
26594173245

push

github

pwelter34
Move JSON support, add docs and examples

1358 of 3215 branches covered (42.24%)

Branch coverage included in aggregate %.

103 of 234 new or added lines in 9 files covered. (44.02%)

371 existing lines in 26 files now uncovered.

4389 of 7130 relevant lines covered (61.56%)

312.89 hits per line

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

50.0
/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
        ArgumentNullException.ThrowIfNull(propertyInfo);
12✔
23

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

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

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

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

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

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

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

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

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

73
        return get(instance);
21✔
74
    }
75

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

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

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