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

Sholtee / proxygen / 980

10 Apr 2025 02:40PM UTC coverage: 91.933% (+0.2%) from 91.686%
980

push

appveyor

Sholtee
test ClassProxyGenerator against system types, related fixes III

4866 of 5293 relevant lines covered (91.93%)

0.92 hits per line

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

73.47
/SRC/Private/Reflection/MetadataMethodInfo.cs
1
/********************************************************************************
2
* MetadataMethodInfo.cs                                                         *
3
*                                                                               *
4
* Author: Denes Solti                                                           *
5
********************************************************************************/
6
using System;
7
using System.Collections.Generic;
8
using System.Collections.Immutable;
9
using System.Diagnostics;
10
using System.Linq;
11
using System.Reflection;
12

13
namespace Solti.Utils.Proxy.Internals
14
{
15
    internal static class MetadataMethodInfo
16
    {
17
        public static IMethodInfo CreateFrom(MethodBase methodBase) => methodBase switch
1✔
18
        {
1✔
19
            ConstructorInfo constructor => new MetadataConstructorInfo(constructor),
1✔
20
            MethodInfo method when method.IsGenericMethod => new MetadataGenericMethodInfo(method), 
1✔
21
            MethodInfo method => new MetadataMethodInfoImpl(method),
1✔
22
            _ => throw new NotSupportedException()
×
23
        };
1✔
24

25
        private abstract class MetadataMethodBase<T>(T method) : IMethodInfo where T: MethodBase
1✔
26
        {
27
            protected T UnderlyingMethod { get; } = method;
1✔
28

29
            [DebuggerBrowsable(DebuggerBrowsableState.Never)]
30
            private IReadOnlyList<IParameterInfo>? FParameters;
31
            public IReadOnlyList<IParameterInfo> Parameters => FParameters ??= UnderlyingMethod
1✔
32
                .GetParameters()
1✔
33
                .Select(MetadataParameterInfo.CreateFrom)
1✔
34
                .ToImmutableList();
1✔
35

36
            public abstract IParameterInfo ReturnValue { get; }
37

38
            public string Name => UnderlyingMethod.StrippedName();
1✔
39

40
            [DebuggerBrowsable(DebuggerBrowsableState.Never)]
41
            private ITypeInfo? FDeclaringType;
42
            public ITypeInfo DeclaringType => FDeclaringType ??= MetadataTypeInfo.CreateFrom(UnderlyingMethod.DeclaringType);
1✔
43

44
            [DebuggerBrowsable(DebuggerBrowsableState.Never)]
45
            private IReadOnlyList<ITypeInfo>? FDeclaringInterfaces;
46
            public IReadOnlyList<ITypeInfo> DeclaringInterfaces => FDeclaringInterfaces ??= UnderlyingMethod
1✔
47
                .GetDeclaringInterfaces()
1✔
48
                .Select(MetadataTypeInfo.CreateFrom)
1✔
49
                .ToImmutableList();
1✔
50

51
            public bool IsStatic => UnderlyingMethod.IsStatic;
1✔
52

53
            public bool IsSpecial => UnderlyingMethod.IsSpecialName;
1✔
54

55
            public bool IsAbstract => UnderlyingMethod.IsAbstract;
1✔
56

57
            public bool IsVirtual => UnderlyingMethod.IsVirtual();
1✔
58

59
            public AccessModifiers AccessModifiers => UnderlyingMethod.GetAccessModifiers();
1✔
60

61
            public override bool Equals(object obj) => obj is MetadataMethodBase<T> that && UnderlyingMethod.Equals(that.UnderlyingMethod);
×
62

63
            public override int GetHashCode() => UnderlyingMethod.GetHashCode();
×
64

65
            public override string ToString() => UnderlyingMethod.ToString();
1✔
66
        }
67

68
        private class MetadataMethodInfoImpl(MethodInfo method) : MetadataMethodBase<MethodInfo>(method)
1✔
69
        {
70
            [DebuggerBrowsable(DebuggerBrowsableState.Never)]
71
            private IParameterInfo? FReturnValue;
72
            public override IParameterInfo ReturnValue => FReturnValue ??= MetadataParameterInfo.CreateFrom(UnderlyingMethod.ReturnParameter);
1✔
73
        }
74

75
        private sealed class MetadataGenericMethodInfo(MethodInfo method) : MetadataMethodInfoImpl(method), IGenericMethodInfo
1✔
76
        {
77
            public bool IsGenericDefinition => UnderlyingMethod.IsGenericMethodDefinition;
1✔
78

79
            [DebuggerBrowsable(DebuggerBrowsableState.Never)]
80
            private IReadOnlyList<ITypeInfo>? FGenericArguments;
81
            public IReadOnlyList<ITypeInfo> GenericArguments => FGenericArguments ??= UnderlyingMethod
1✔
82
                .GetGenericArguments()
1✔
83
                .Select(MetadataTypeInfo.CreateFrom)
1✔
84
                .ToImmutableList();
1✔
85

86
            [DebuggerBrowsable(DebuggerBrowsableState.Never)]
87
            private IGenericMethodInfo? FGenericDefinition;
88
            public IGenericMethodInfo GenericDefinition => FGenericDefinition ??= new MetadataGenericMethodInfo
×
89
            (
×
90
                UnderlyingMethod.GetGenericMethodDefinition()
×
91
            );
×
92

93
            [DebuggerBrowsable(DebuggerBrowsableState.Never)]
94
            private IReadOnlyList<IGenericConstraint>? FGenericConstraints;
95
            public IReadOnlyList<IGenericConstraint> GenericConstraints => FGenericConstraints ??= !IsGenericDefinition
×
96
                ? ImmutableList.Create<IGenericConstraint>()
×
97
                : UnderlyingMethod
×
98
                    .GetGenericArguments()
×
99
                    .Select(ga => MetadataGenericConstraint.CreateFrom(ga, UnderlyingMethod)!)
1✔
100
                    .Where(static c => c is not null)
1✔
101
                    .ToImmutableList();
×
102

103
            public IGenericMethodInfo Close(params ITypeInfo[] genericArgs) =>
104
                //
105
                // We never specialize open generic methods
106
                //
107

108
                throw new NotImplementedException();
×
109
        }
110

111
        private sealed class MetadataConstructorInfo(ConstructorInfo method) : MetadataMethodBase<ConstructorInfo>(method), IConstructorInfo 
1✔
112
        {
113
            public override IParameterInfo ReturnValue { get; } = null!;
1✔
114
        }
115
    }
116
}
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