Skip to content

Commit 9aab74d

Browse files
authored
Small refactoring to reuse conditional logic. (#41154)
1 parent 4f7db06 commit 9aab74d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public static ImmutableArray<FunctionPointerParameterSymbol> MakeFunctionPointer
7878
SyntaxToken paramsKeyword, SyntaxToken thisKeyword, bool addRefReadOnlyModifier,
7979
DiagnosticBag diagnostics) =>
8080
{
81-
82-
var customModifiers = addRefReadOnlyModifier && refKind == RefKind.In ?
83-
CreateInModifiers(binder, diagnostics, syntax) :
84-
ImmutableArray<CustomModifier>.Empty;
81+
ImmutableArray<CustomModifier> customModifiers = CreateInModifiers(refKind, addRefReadOnlyModifier, binder, diagnostics, syntax);
8582

8683
if (parameterType.IsVoidType())
8784
{
@@ -689,10 +686,17 @@ private static RefKind GetModifiers(SyntaxTokenList modifiers, out SyntaxToken r
689686
return refKind;
690687
}
691688

692-
internal static ImmutableArray<CustomModifier> CreateInModifiers(Binder binder, DiagnosticBag diagnostics, SyntaxNode syntax)
689+
internal static ImmutableArray<CustomModifier> CreateInModifiers(RefKind refKind, bool addRefReadOnlyModifier, Binder binder, DiagnosticBag diagnostics, SyntaxNode syntax)
693690
{
694-
var modifierType = binder.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_InAttribute, diagnostics, syntax);
695-
return ImmutableArray.Create(CSharpCustomModifier.CreateRequired(modifierType));
691+
if (addRefReadOnlyModifier && refKind == RefKind.In)
692+
{
693+
var modifierType = binder.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_InAttribute, diagnostics, syntax);
694+
return ImmutableArray.Create(CSharpCustomModifier.CreateRequired(modifierType));
695+
}
696+
else
697+
{
698+
return ImmutableArray<CustomModifier>.Empty;
699+
}
696700
}
697701
}
698702
}

src/Compilers/CSharp/Portable/Symbols/Source/SourceParameterSymbol.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ public static SourceParameterSymbol Create(
4949
identifier.Parent.GetLocation());
5050
}
5151

52-
if (addRefReadOnlyModifier && refKind == RefKind.In)
52+
ImmutableArray<CustomModifier> inModifiers = ParameterHelpers.CreateInModifiers(refKind, addRefReadOnlyModifier, context, declarationDiagnostics, syntax);
53+
54+
if (!inModifiers.IsDefaultOrEmpty)
5355
{
5456
return new SourceComplexParameterSymbolWithCustomModifiersPrecedingByRef(
5557
owner,
5658
ordinal,
5759
parameterType,
5860
refKind,
59-
ParameterHelpers.CreateInModifiers(context, declarationDiagnostics, syntax),
61+
inModifiers,
6062
name,
6163
locations,
6264
syntax.GetReference(),

0 commit comments

Comments
 (0)