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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 hits per line

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

0.0
/src/ACadSharp/PropertyReflection.cs
1
using System;
2
using System.Collections.Concurrent;
3
using System.Collections.Generic;
4
using System.Linq.Expressions;
5
using System.Reflection;
6

7
namespace ACadSharp
8
{
9
        internal class PropertyExpression<TClass, TAttribute>
10
                where TClass : class
11
                where TAttribute : Attribute
12
        {
13
                public class Prop
14
                {
15
                        public Func<TClass, object> Getter { get; internal set; }
×
16

17
                        public Action<TClass, object> Setter { get; internal set; }
×
18

19
                        public TAttribute Attribute { get; internal set; }
×
20

21
                        public PropertyInfo Property { get; internal set; }
×
22
                }
23

24
                private static readonly ConcurrentDictionary<string, Prop> _cache = new ConcurrentDictionary<string, Prop>();
×
25

26
                public IReadOnlyDictionary<string, Prop> Cache = _cache;
×
27

28
                public PropertyExpression(Func<PropertyInfo, TAttribute, string> keySelector)
×
29
                {
×
30
                        var properties = typeof(TClass).GetProperties();
×
31
                        foreach (var property in properties)
×
32
                        {
×
33
                                var attribute = property.GetCustomAttribute<TAttribute>();
×
34
                                if (attribute == null)
×
35
                                        continue;
×
36

37
                                var eventLogCustomType = property.DeclaringType;
×
38
                                var propertyType = property.PropertyType;
×
39

40
                                var instance = Expression.Parameter(typeof(TClass));
×
41

42
                                Func<TClass, object> getter = null;
×
43
                                var getMethod = property.GetGetMethod(true);
×
44
                                if (getMethod != null)
×
45
                                {
×
46
                                        getter =
×
47
                                                Expression.Lambda<Func<TClass, object>>(
×
48
                                                                Expression.Convert(
×
49
                                                                        Expression.Call(
×
50
                                                                                Expression.Convert(instance, eventLogCustomType),
×
51
                                                                                getMethod),
×
52
                                                                        typeof(object)),
×
53
                                                                instance)
×
54
                                                        .Compile();
×
55
                                }
×
56

57
                                Action<TClass, object> setter = null;
×
58
                                var setMethod = property.GetSetMethod(true);
×
59
                                if (setMethod != null)
×
60
                                {
×
61
                                        var parameter = Expression.Parameter(typeof(object));
×
62
                                        setter =
×
63
                                                Expression.Lambda<Action<TClass, object>>(
×
64
                                                                Expression.Call(
×
65
                                                                        Expression.Convert(instance, eventLogCustomType),
×
66
                                                                        setMethod,
×
67
                                                                        Expression.Convert(parameter, propertyType)),
×
68
                                                                instance, parameter)
×
69
                                                        .Compile();
×
70
                                }
×
71

72
                                _cache.TryAdd(keySelector(property, attribute), new Prop
×
73
                                {
×
74
                                        Getter = getter,
×
75
                                        Setter = setter,
×
76
                                        Attribute = attribute,
×
77
                                        Property = property
×
78
                                });
×
79
                        }
×
80
                }
×
81

82
                public Prop GetProperty(string propName)
83
                {
×
84
                        return _cache[propName];
×
85
                }
×
86
        }
87
}
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