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

Sholtee / proxygen / 816

pending completion
816

push

appveyor

D,nes Solti
greenify tests

2435 of 2558 relevant lines covered (95.19%)

2.85 hits per line

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

86.11
/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.Reflection;
10

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

23
        private abstract class MetadataMethodBase<T>: IMethodInfo where T: MethodBase
24
        {
25
            protected T UnderlyingMethod { get; }
3✔
26

27
            protected MetadataMethodBase(T method) => UnderlyingMethod = method;
3✔
28

29
            private IReadOnlyList<IParameterInfo>? FParameters;
30
            public IReadOnlyList<IParameterInfo> Parameters => FParameters ??= UnderlyingMethod.GetParameters().ConvertAr(MetadataParameterInfo.CreateFrom);
3✔
31

32
            public abstract IParameterInfo ReturnValue { get; }
33

34
            public string Name => UnderlyingMethod.StrippedName();
3✔
35

36
            private ITypeInfo? FDeclaringType;
37
            public ITypeInfo DeclaringType => FDeclaringType ??= MetadataTypeInfo.CreateFrom(UnderlyingMethod.DeclaringType);
3✔
38

39
            private IReadOnlyList<ITypeInfo>? FDeclaringInterfaces;
40
            public IReadOnlyList<ITypeInfo> DeclaringInterfaces => FDeclaringInterfaces ??= UnderlyingMethod.GetDeclaringInterfaces().ConvertAr(MetadataTypeInfo.CreateFrom);
3✔
41

42
            public bool IsStatic => UnderlyingMethod.IsStatic;
3✔
43

44
            public bool IsSpecial => UnderlyingMethod.IsSpecial();
3✔
45

46
            public AccessModifiers AccessModifiers => UnderlyingMethod.GetAccessModifiers();
3✔
47

48
            public bool IsFinal => UnderlyingMethod.IsFinal();
3✔
49

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

52
            public override int GetHashCode() => UnderlyingMethod.GetHashCode();
×
53

54
            public override string ToString() => UnderlyingMethod.ToString();
3✔
55
        }
56

57
        private class MetadataMethodInfoImpl : MetadataMethodBase<MethodInfo>
58
        {
59
            public MetadataMethodInfoImpl(MethodInfo method) : base(method) { }
3✔
60

61
            private IParameterInfo? FReturnValue;
62
            public override IParameterInfo ReturnValue => FReturnValue ??= MetadataParameterInfo.CreateFrom(UnderlyingMethod.ReturnParameter);
3✔
63
        }
64

65
        private sealed class MetadataGenericMethodInfo : MetadataMethodInfoImpl, IGenericMethodInfo
66
        {
67
            public MetadataGenericMethodInfo(MethodInfo method) : base(method) { }
3✔
68

69
            public bool IsGenericDefinition => UnderlyingMethod.IsGenericMethodDefinition;
3✔
70

71
            private IReadOnlyList<ITypeInfo>? FGenericArguments;
72
            public IReadOnlyList<ITypeInfo> GenericArguments => FGenericArguments ??= UnderlyingMethod.GetGenericArguments().ConvertAr(MetadataTypeInfo.CreateFrom);
3✔
73

74
            private IGenericMethodInfo? FGenericDefinition;
75
            public IGenericMethodInfo GenericDefinition => FGenericDefinition ??= new MetadataGenericMethodInfo
×
76
            (
77
                UnderlyingMethod.GetGenericMethodDefinition()
78
            );
79

80
            private IEnumerable<IGenericConstraint> GetConstraints()
81
            {
3✔
82
                foreach (Type ga in UnderlyingMethod.GetGenericArguments())
3✔
83
                {
3✔
84
                    IGenericConstraint? constraint = MetadataGenericConstraint.CreateFrom(ga);
3✔
85
                    if (constraint is not null)
3✔
86
                        yield return constraint;
3✔
87
                }
3✔
88
            }
3✔
89

90
            private IReadOnlyList<IGenericConstraint>? FGenericConstraints;
91
            public IReadOnlyList<IGenericConstraint> GenericConstraints => FGenericConstraints ??= !IsGenericDefinition
3✔
92
                ? Array.Empty<IGenericConstraint>()
93
                : ImmutableList
94
                    .Create<IGenericConstraint>()
95
                    .AddRange(GetConstraints());
96

97
            public IGenericMethodInfo Close(params ITypeInfo[] genericArgs) => throw new NotImplementedException(); // Nincs ra szukseg
×
98
        }
99

100
        private sealed class MetadataConstructorInfo : MetadataMethodBase<ConstructorInfo>, IConstructorInfo 
101
        {
102
            public MetadataConstructorInfo(ConstructorInfo method) : base(method) { }
3✔
103

104
            public override IParameterInfo ReturnValue { get; } = null!;
3✔
105
        }
106
    }
107
}
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