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

Sholtee / proxygen / 957

03 Apr 2025 03:49AM UTC coverage: 90.283% (+3.1%) from 87.222%
957

push

appveyor

Sholtee
fix method hash generation

4841 of 5362 relevant lines covered (90.28%)

0.9 hits per line

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

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

11
using Microsoft.CodeAnalysis;
12

13
namespace Solti.Utils.Proxy.Internals
14
{
15
    internal class SymbolMethodInfo : IMethodInfo, IConstructorInfo
16
    {
17
        private IMethodSymbol UnderlyingSymbol { get; }
1✔
18

19
        private Compilation Compilation { get; }
1✔
20

21
        protected SymbolMethodInfo(IMethodSymbol method, Compilation compilation) 
1✔
22
        {
1✔
23
            UnderlyingSymbol = method;
1✔
24
            Compilation = compilation;
1✔
25
        }
1✔
26

27
        public static IMethodInfo CreateFrom(IMethodSymbol method, Compilation compilation)
28
        {
1✔
29
            method.EnsureNotError();
1✔
30

31
            return method switch
1✔
32
            {
1✔
33
                _ when method.TypeArguments.Length > 0 => new SymbolGenericMethodInfo(method, compilation),
1✔
34
                _ => new SymbolMethodInfo(method, compilation)
1✔
35
            };
1✔
36
        }
1✔
37

38
        private IReadOnlyList<IParameterInfo>? FParameters;
39
        public IReadOnlyList<IParameterInfo> Parameters => FParameters ??= UnderlyingSymbol
1✔
40
            .Parameters
1✔
41
            .Select(p => SymbolParameterInfo.CreateFrom(p, Compilation))
1✔
42
            .ToImmutableList();
1✔
43

44
        private IParameterInfo? FReturnValue;
45
        public IParameterInfo ReturnValue => FReturnValue ??= UnderlyingSymbol.MethodKind != MethodKind.Constructor
1✔
46
            ? SymbolReturnParameterInfo.CreateFrom(UnderlyingSymbol, Compilation)
1✔
47
            : null!;
1✔
48

49
        private bool? FIsSpecial;
50
        public bool IsSpecial => FIsSpecial ??= UnderlyingSymbol.IsSpecial();
1✔
51

52
        public bool IsAbstract => UnderlyingSymbol.IsAbstract;
1✔
53

54
        public bool IsVirtual => UnderlyingSymbol.IsVirtual();
1✔
55

56
        public AccessModifiers AccessModifiers => UnderlyingSymbol.GetAccessModifiers();
1✔
57

58
        private ITypeInfo? FDeclaringType;
59
        public ITypeInfo DeclaringType => FDeclaringType ??= SymbolTypeInfo.CreateFrom(UnderlyingSymbol.ContainingType, Compilation);
1✔
60

61
        private IReadOnlyList<ITypeInfo>? FDeclaringInterfaces;
62
        public IReadOnlyList<ITypeInfo> DeclaringInterfaces => FDeclaringInterfaces ??= UnderlyingSymbol
1✔
63
            .GetDeclaringInterfaces()
1✔
64
            .Select(di => SymbolTypeInfo.CreateFrom(di, Compilation))
1✔
65
            .ToImmutableList();
1✔
66

67
        public bool IsStatic => UnderlyingSymbol.IsStatic;
1✔
68

69
        public string Name => UnderlyingSymbol.StrippedName();
1✔
70

71
        public override bool Equals(object obj) => obj is SymbolMethodInfo that && SymbolEqualityComparer.Default.Equals(that.UnderlyingSymbol, UnderlyingSymbol);
×
72

73
        public override int GetHashCode() => SymbolEqualityComparer.Default.GetHashCode(UnderlyingSymbol);
×
74

75
        public override string ToString() => UnderlyingSymbol.ToString();
×
76

77
        private sealed class SymbolGenericMethodInfo : SymbolMethodInfo, IGenericMethodInfo 
78
        {
79
            public SymbolGenericMethodInfo(IMethodSymbol method, Compilation compilation) : base(method, compilation) { }
1✔
80

81
            private bool? FIsGenericDefinition;
82
            public bool IsGenericDefinition => FIsGenericDefinition ??= !UnderlyingSymbol
×
83
                .TypeParameters
×
84
                .Any(static tp => !SymbolEqualityComparer.Default.Equals(tp.OriginalDefinition, tp));
1✔
85

86
            private IGenericMethodInfo? FGenericDefinition;
87
            public IGenericMethodInfo GenericDefinition => FGenericDefinition ??= new SymbolGenericMethodInfo(UnderlyingSymbol.OriginalDefinition, Compilation);
×
88

89
            private IReadOnlyList<ITypeInfo>? FGenericArguments;
90
            public IReadOnlyList<ITypeInfo> GenericArguments => FGenericArguments ??= UnderlyingSymbol
1✔
91
                .TypeArguments
1✔
92
                .Select(ta => SymbolTypeInfo.CreateFrom(ta, Compilation))
1✔
93
                .ToImmutableList();
1✔
94

95
            private IReadOnlyList<IGenericConstraint>? FGenericConstraints;
96
            public IReadOnlyList<IGenericConstraint> GenericConstraints => FGenericConstraints ??= UnderlyingSymbol
1✔
97
                .TypeParameters
1✔
98
                .Select(gc => SymbolGenericConstraint.CreateFrom(gc, Compilation)!)
1✔
99
                .Where(static gc => gc is not null)
1✔
100
                .ToImmutableList();
1✔
101

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

107
                throw new NotImplementedException();
×
108
        }
109
    }
110
}
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

© 2025 Coveralls, Inc