Repository navigation
Expand file tree
/
Copy pathContainingType.cs
More file actions
42 lines (38 loc) · 2.02 KB
/
Copy pathContainingType.cs
File metadata and controls
42 lines (38 loc) · 2.02 KB
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
// <auto-generated/>
// Zomp.MethodCloning, compiled into the generator which references the package. Marked as
// generated so that the analyzers of that generator leave it alone.
#nullable enable
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Immutable;
using System.Linq;
namespace Zomp.MethodCloning;
/// <summary>
/// A type a method is nested in, which the copy of the method declares again, as partial,
/// around itself.
/// </summary>
/// <param name="Kind">Kind of the type.</param>
/// <param name="Name">Name of the type, without its type parameters.</param>
/// <param name="Modifiers">Modifiers of the type other than <c>partial</c>, as raw syntax kinds.</param>
/// <param name="TypeParameters">Names of the type parameters of the type.</param>
/// <param name="ClassOrStructKeyword">For a record, the <c>class</c> or <c>struct</c> keyword, when one is written.</param>
internal sealed record ContainingType(ContainingTypeKind Kind, string Name, EquatableArray<ushort> Modifiers, EquatableArray<string> TypeParameters, SyntaxToken ClassOrStructKeyword)
{
public ContainingType(ContainingTypeKind kind, SyntaxToken name, SyntaxTokenList modifiers, TypeParameterListSyntax? typeParameterList, SyntaxToken classOrStructKeyword = default)
: this(
kind,
name.ValueText,
modifiers.Select(z => (ushort)z.RawKind).Where(z => z != (ushort)SyntaxKind.PartialKeyword).ToImmutableArray(),
(typeParameterList is null ? [] : typeParameterList.Parameters.Select(z => z.Identifier.ValueText)).ToImmutableArray(),
classOrStructKeyword)
{
}
/// <summary>
/// Gets the name of the type with its type parameters, so that <c>Class</c>, <c>Class{T}</c>
/// and <c>Class{T,T2}</c> stay distinct.
/// </summary>
public string ScopeName => TypeParameters.IsEmpty
? Name
: Name + "{" + string.Join(",", TypeParameters) + "}";
}