-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSourceMethodInfo.cs
31 lines (23 loc) · 1009 Bytes
/
SourceMethodInfo.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
using System.Reflection;
namespace SourceGeneration.Reflection;
public class SourceMethodInfo(Func<MethodInfo> getMethodInfo) : SourceMethodBase
{
private MethodInfo? _methodInfo;
private Func<object?, object?[]?, object?>? _invoke;
public MethodInfo MethodInfo => _methodInfo ??= getMethodInfo();
#if NET5_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(ReflectionExtensions.DefaultAccessMembers)]
#endif
private Type? _returnType;
public Type ReturnType
{
get => _returnType ??= MethodInfo.ReturnType;
init => _returnType = value;
}
public SourceNullableAnnotation ReturnNullableAnnotation { get; init; } = default!;
public Func<object?, object?[]?, object?> Invoke
{
get => _invoke ?? (MethodInfo.IsGenericMethodDefinition ? throw new InvalidOperationException("This method has a generic parameter. Please use MethodInfo.Invoke instead.") : MethodInfo.Invoke);
init => _invoke = value;
}
}