-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSourcePropertyInfo.cs
70 lines (53 loc) · 2.25 KB
/
SourcePropertyInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Reflection;
namespace SourceGeneration.Reflection;
public class SourcePropertyInfo(Func<PropertyInfo> propertyInfoAccess) : SourceMemberInfo, ISourceFieldOrPropertyInfo
{
private Func<object?, object?>? _getMethod;
private Action<object?, object?>? _setMethod;
private Func<object?, object?[]?, object?>? _getIndexerMethod;
private Action<object?, object?, object?[]?>? _setIndexerMethod;
private PropertyInfo? _propertyInfo;
public PropertyInfo PropertyInfo => _propertyInfo ??= propertyInfoAccess();
public SourceAccessibility Accessibility { get; init; }
#if NET5_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(ReflectionExtensions.DefaultAccessMembers)]
#endif
public Type PropertyType { get; init; } = default!;
public bool IsVirtual { get; init; }
public bool IsRequired { get; init; }
public bool IsAbstract { get; init; }
public bool IsStatic { get; init; }
public bool IsInitOnly { get; init; }
public bool IsIndexer { get; init; }
public bool IsGenericDictionaryType { get; init; }
public bool IsGenericEnumerableType { get; init; }
public SourceParameterInfo[] IndexerParameters { get; init; } = [];
public SourceNullableAnnotation NullableAnnotation { get; init; }
public bool CanWrite { get; init; }
public bool CanRead { get; init; }
public Func<object?, object?> GetValue
{
get => _getMethod ?? PropertyInfo.GetValue;
init => _getMethod = value;
}
public Action<object?, object?> SetValue
{
get => _setMethod ?? PropertyInfo.SetValue;
init => _setMethod = value;
}
public Action<object?, object?, object?[]?> SetIndexerValue
{
get => _setIndexerMethod ?? PropertyInfo.SetValue;
init => _setIndexerMethod = value;
}
public Func<object?, object?[]?, object?> GetIndexerValue
{
get => _getIndexerMethod ?? PropertyInfo.GetValue;
init => _getIndexerMethod = value;
}
#if NET5_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(ReflectionExtensions.DefaultAccessMembers)]
#endif
Type ISourceFieldOrPropertyInfo.MemberType => PropertyType;
MemberInfo ISourceFieldOrPropertyInfo.MemberInfo => PropertyInfo;
}