/
SymbolDisplayExtensions.cs
131 lines (118 loc) · 5.55 KB
/
SymbolDisplayExtensions.cs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.PooledObjects;
namespace Microsoft.CodeAnalysis
{
/// <summary>
/// Exposes extension methods for displaying symbol descriptions.
/// </summary>
public static class SymbolDisplayExtensions
{
/// <summary>
/// Converts an immutable array of <see cref="SymbolDisplayPart"/>s to a string.
/// </summary>
/// <param name="parts">The array of parts.</param>
/// <returns>The concatenation of the parts into a single string.</returns>
public static string ToDisplayString(this ImmutableArray<SymbolDisplayPart> parts)
{
if (parts.IsDefault)
{
throw new ArgumentException("parts");
}
if (parts.Length == 0)
{
return string.Empty;
}
if (parts.Length == 1)
{
return parts[0].ToString();
}
var pool = PooledStringBuilder.GetInstance();
try
{
var actualBuilder = pool.Builder;
foreach (var part in parts)
{
actualBuilder.Append(part);
}
return actualBuilder.ToString();
}
finally
{
pool.Free();
}
}
/// <summary>
/// Determines if a flag is set on the <see cref="SymbolDisplayCompilerInternalOptions"/> enum.
/// </summary>
/// <param name="options">The value to check.</param>
/// <param name="flag">An enum field that specifies the flag.</param>
/// <returns>Whether the <paramref name="flag"/> is set on the <paramref name="options"/>.</returns>
internal static bool IncludesOption(this SymbolDisplayCompilerInternalOptions options, SymbolDisplayCompilerInternalOptions flag)
{
return (options & flag) == flag;
}
/// <summary>
/// Determines if a flag is set on the <see cref="SymbolDisplayGenericsOptions"/> enum.
/// </summary>
/// <param name="options">The value to check.</param>
/// <param name="flag">An enum field that specifies the flag.</param>
/// <returns>Whether the <paramref name="flag"/> is set on the <paramref name="options"/>.</returns>
internal static bool IncludesOption(this SymbolDisplayGenericsOptions options, SymbolDisplayGenericsOptions flag)
{
return (options & flag) == flag;
}
/// <summary>
/// Determines if a flag is set on the <see cref="SymbolDisplayMemberOptions"/> enum.
/// </summary>
/// <param name="options">The value to check.</param>
/// <param name="flag">An enum field that specifies the flag.</param>
/// <returns>Whether the <paramref name="flag"/> is set on the <paramref name="options"/>.</returns>
internal static bool IncludesOption(this SymbolDisplayMemberOptions options, SymbolDisplayMemberOptions flag)
{
return (options & flag) == flag;
}
/// <summary>
/// Determines if a flag is set on the <see cref="SymbolDisplayMiscellaneousOptions"/> enum.
/// </summary>
/// <param name="options">The value to check.</param>
/// <param name="flag">An enum field that specifies the flag.</param>
/// <returns>Whether the <paramref name="flag"/> is set on the <paramref name="options"/>.</returns>
internal static bool IncludesOption(this SymbolDisplayMiscellaneousOptions options, SymbolDisplayMiscellaneousOptions flag)
{
return (options & flag) == flag;
}
/// <summary>
/// Determines if a flag is set on the <see cref="SymbolDisplayParameterOptions"/> enum.
/// </summary>
/// <param name="options">The value to check.</param>
/// <param name="flag">An enum field that specifies the flag.</param>
/// <returns>Whether the <paramref name="flag"/> is set on the <paramref name="options"/>.</returns>
internal static bool IncludesOption(this SymbolDisplayParameterOptions options, SymbolDisplayParameterOptions flag)
{
return (options & flag) == flag;
}
/// <summary>
/// Determines if a flag is set on the <see cref="SymbolDisplayKindOptions"/> enum.
/// </summary>
/// <param name="options">The value to check.</param>
/// <param name="flag">An enum field that specifies the flag.</param>
/// <returns>Whether the <paramref name="flag"/> is set on the <paramref name="options"/>.</returns>
internal static bool IncludesOption(this SymbolDisplayKindOptions options, SymbolDisplayKindOptions flag)
{
return (options & flag) == flag;
}
/// <summary>
/// Determines if a flag is set on the <see cref="SymbolDisplayLocalOptions"/> enum.
/// </summary>
/// <param name="options">The value to check.</param>
/// <param name="flag">An enum field that specifies the flag.</param>
/// <returns>Whether the <paramref name="flag"/> is set on the <paramref name="options"/>.</returns>
internal static bool IncludesOption(this SymbolDisplayLocalOptions options, SymbolDisplayLocalOptions flag)
{
return (options & flag) == flag;
}
}
}