@@ -25,19 +25,14 @@ public override void Populate(TextWriter trapFile)
25
25
26
26
public static string AccessibilityModifier ( Accessibility access )
27
27
{
28
- switch ( access )
28
+ return access switch
29
29
{
30
- case Accessibility . Private :
31
- return "private" ;
32
- case Accessibility . Protected :
33
- return "protected" ;
34
- case Accessibility . Public :
35
- return "public" ;
36
- case Accessibility . Internal :
37
- return "internal" ;
38
- default :
39
- throw new InternalError ( "Unavailable modifier combination" ) ;
40
- }
30
+ Accessibility . Private => Modifiers . Private ,
31
+ Accessibility . Protected => Modifiers . Protected ,
32
+ Accessibility . Public => Modifiers . Public ,
33
+ Accessibility . Internal => Modifiers . Internal ,
34
+ _ => throw new InternalError ( "Unavailable modifier combination" ) ,
35
+ } ;
41
36
}
42
37
43
38
public static void HasAccessibility ( Context cx , TextWriter trapFile , IEntity type , Accessibility access )
@@ -48,17 +43,17 @@ public static void HasAccessibility(Context cx, TextWriter trapFile, IEntity typ
48
43
case Accessibility . Public :
49
44
case Accessibility . Protected :
50
45
case Accessibility . Internal :
51
- HasModifier ( cx , trapFile , type , Modifier . AccessibilityModifier ( access ) ) ;
46
+ HasModifier ( cx , trapFile , type , AccessibilityModifier ( access ) ) ;
52
47
break ;
53
48
case Accessibility . NotApplicable :
54
49
break ;
55
50
case Accessibility . ProtectedOrInternal :
56
- HasModifier ( cx , trapFile , type , "protected" ) ;
57
- HasModifier ( cx , trapFile , type , "internal" ) ;
51
+ HasModifier ( cx , trapFile , type , Modifiers . Protected ) ;
52
+ HasModifier ( cx , trapFile , type , Modifiers . Internal ) ;
58
53
break ;
59
54
case Accessibility . ProtectedAndInternal :
60
- HasModifier ( cx , trapFile , type , "protected" ) ;
61
- HasModifier ( cx , trapFile , type , "private" ) ;
55
+ HasModifier ( cx , trapFile , type , Modifiers . Protected ) ;
56
+ HasModifier ( cx , trapFile , type , Modifiers . Private ) ;
62
57
break ;
63
58
default :
64
59
throw new InternalError ( $ "Unhandled Microsoft.CodeAnalysis.Accessibility value: { access } ") ;
@@ -70,58 +65,63 @@ public static void HasModifier(Context cx, TextWriter trapFile, IEntity target,
70
65
trapFile . has_modifiers ( target , Modifier . Create ( cx , modifier ) ) ;
71
66
}
72
67
68
+ private static void ExtractNamedTypeModifiers ( Context cx , TextWriter trapFile , IEntity key , ISymbol symbol )
69
+ {
70
+ if ( symbol . Kind != SymbolKind . NamedType )
71
+ return ;
72
+
73
+ if ( symbol is not INamedTypeSymbol nt )
74
+ throw new InternalError ( symbol , "Symbol kind is inconsistent with its type" ) ;
75
+
76
+ if ( nt . IsRecord )
77
+ HasModifier ( cx , trapFile , key , Modifiers . Record ) ;
78
+
79
+ if ( nt . TypeKind == TypeKind . Struct )
80
+ {
81
+ if ( nt . IsReadOnly )
82
+ HasModifier ( cx , trapFile , key , Modifiers . Readonly ) ;
83
+
84
+ if ( nt . IsRefLikeType )
85
+ HasModifier ( cx , trapFile , key , Modifiers . Ref ) ;
86
+ }
87
+ }
88
+
73
89
public static void ExtractModifiers ( Context cx , TextWriter trapFile , IEntity key , ISymbol symbol )
74
90
{
75
91
HasAccessibility ( cx , trapFile , key , symbol . DeclaredAccessibility ) ;
76
92
if ( symbol . Kind == SymbolKind . ErrorType )
77
93
trapFile . has_modifiers ( key , Modifier . Create ( cx , Accessibility . Public ) ) ;
78
94
79
95
if ( symbol . IsAbstract && ( symbol . Kind != SymbolKind . NamedType || ( ( INamedTypeSymbol ) symbol ) . TypeKind != TypeKind . Interface ) )
80
- HasModifier ( cx , trapFile , key , "abstract" ) ;
96
+ HasModifier ( cx , trapFile , key , Modifiers . Abstract ) ;
81
97
82
98
if ( symbol . IsSealed )
83
- HasModifier ( cx , trapFile , key , "sealed" ) ;
99
+ HasModifier ( cx , trapFile , key , Modifiers . Sealed ) ;
84
100
85
101
var fromSource = symbol . DeclaringSyntaxReferences . Length > 0 ;
86
102
87
103
if ( symbol . IsStatic && ! ( symbol . Kind == SymbolKind . Field && ( ( IFieldSymbol ) symbol ) . IsConst && ! fromSource ) )
88
- HasModifier ( cx , trapFile , key , "static" ) ;
104
+ HasModifier ( cx , trapFile , key , Modifiers . Static ) ;
89
105
90
106
if ( symbol . IsVirtual )
91
- HasModifier ( cx , trapFile , key , "virtual" ) ;
107
+ HasModifier ( cx , trapFile , key , Modifiers . Virtual ) ;
92
108
93
109
if ( symbol . Kind == SymbolKind . Field && ( ( IFieldSymbol ) symbol ) . IsReadOnly )
94
- HasModifier ( cx , trapFile , key , "readonly" ) ;
110
+ HasModifier ( cx , trapFile , key , Modifiers . Readonly ) ;
95
111
96
112
if ( symbol . IsOverride )
97
- HasModifier ( cx , trapFile , key , "override" ) ;
113
+ HasModifier ( cx , trapFile , key , Modifiers . Override ) ;
98
114
99
115
if ( symbol . Kind == SymbolKind . Method && ( ( IMethodSymbol ) symbol ) . IsAsync )
100
- HasModifier ( cx , trapFile , key , "async" ) ;
116
+ HasModifier ( cx , trapFile , key , Modifiers . Async ) ;
101
117
102
118
if ( symbol . IsExtern )
103
- HasModifier ( cx , trapFile , key , "extern" ) ;
119
+ HasModifier ( cx , trapFile , key , Modifiers . Extern ) ;
104
120
105
121
foreach ( var modifier in symbol . GetSourceLevelModifiers ( ) )
106
122
HasModifier ( cx , trapFile , key , modifier ) ;
107
123
108
- if ( symbol . Kind == SymbolKind . NamedType )
109
- {
110
- var nt = symbol as INamedTypeSymbol ;
111
- if ( nt is null )
112
- throw new InternalError ( symbol , "Symbol kind is inconsistent with its type" ) ;
113
-
114
- if ( nt . IsRecord )
115
- HasModifier ( cx , trapFile , key , "record" ) ;
116
-
117
- if ( nt . TypeKind == TypeKind . Struct )
118
- {
119
- if ( nt . IsReadOnly )
120
- HasModifier ( cx , trapFile , key , "readonly" ) ;
121
- if ( nt . IsRefLikeType )
122
- HasModifier ( cx , trapFile , key , "ref" ) ;
123
- }
124
- }
124
+ ExtractNamedTypeModifiers ( cx , trapFile , key , symbol ) ;
125
125
}
126
126
127
127
public static Modifier Create ( Context cx , string modifier )
0 commit comments