blob: 6ee65cbb9e893e11bdebcd351d9754c187638bf7 (
plain)
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
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using ILLink.RoslynAnalyzer;
using Microsoft.CodeAnalysis;
namespace ILLink.Shared.TypeSystemProxy
{
partial struct ParameterProxy
{
public ParameterProxy (IParameterSymbol parameter)
{
Method = (new ((IMethodSymbol) parameter.ContainingSymbol));
Index = (ParameterIndex) parameter.Ordinal + (Method.HasImplicitThis () ? 1 : 0);
}
public partial ReferenceKind GetReferenceKind () =>
IsImplicitThis
? ((ITypeSymbol) Method.Method.ContainingSymbol).IsValueType
? ReferenceKind.Ref
: ReferenceKind.None
: Method.Method.Parameters[MetadataIndex].RefKind switch {
RefKind.Ref => ReferenceKind.Ref,
RefKind.In => ReferenceKind.In,
RefKind.Out => ReferenceKind.Out,
RefKind.None => ReferenceKind.None,
_ => throw new NotImplementedException ($"Unexpected RefKind found on parameter {GetDisplayName ()}")
};
/// <summary>
/// Returns the IParameterSymbol representing the parameter. Returns null for the implicit this paramter.
/// </summary>
public IParameterSymbol? ParameterSymbol => IsImplicitThis ? null : Method.Method.Parameters[MetadataIndex];
/// <summary>
/// Returns the IParameterSymbol.Location[0] for the parameter. Returns null for the implicit this paramter.
/// </summary>
public Location? Location => ParameterSymbol?.Locations[0];
public TypeProxy ParameterType
=> IsImplicitThis
? new TypeProxy (Method.Method.ContainingType)
: new TypeProxy (Method.Method.Parameters[MetadataIndex].Type);
public partial string GetDisplayName ()
{
if (IsImplicitThis)
return "this";
return ParameterSymbol!.GetDisplayName ();
}
public partial bool IsTypeOf (string typeName) => ParameterType.IsTypeOf (typeName.Substring (0, typeName.LastIndexOf ('.')), typeName.Substring (1 + typeName.LastIndexOf ('.')));
public bool IsTypeOf (WellKnownType type) => ParameterType.IsTypeOf (type);
}
}
|