Skip to content

Commit d785549

Browse files
Update code to use null propagation (#78733)
2 parents a8808be + 128e99c commit d785549

File tree

13 files changed

+16
-58
lines changed

13 files changed

+16
-58
lines changed

src/EditorFeatures/CSharpTest/CodeActions/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ private static OptionsCollection PreferExplicitTypeWithInfo()
6969
internal static void EnableOption(ImmutableArray<PickMembersOption> options, string id)
7070
{
7171
var option = options.FirstOrDefault(o => o.Id == id);
72-
if (option != null)
73-
{
74-
option.Value = true;
75-
}
72+
option?.Value = true;
7673
}
7774

7875
[Fact]

src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,12 +806,9 @@ private async Task<bool> CommitWorkerAsync(bool previewChanges, bool canUseBackg
806806

807807
previewChanges = previewChanges || PreviewChanges;
808808

809-
if (editorUIOperationContext is not null)
810-
{
811-
// Prevent Editor's typing responsiveness auto canceling the rename operation.
812-
// InlineRenameSession will call IUIThreadOperationExecutor to sets up our own IUIThreadOperationContext
813-
editorUIOperationContext.TakeOwnership();
814-
}
809+
// Prevent Editor's typing responsiveness auto canceling the rename operation.
810+
// InlineRenameSession will call IUIThreadOperationExecutor to sets up our own IUIThreadOperationContext
811+
editorUIOperationContext?.TakeOwnership();
815812

816813
try
817814
{

src/EditorFeatures/Core/InlineRename/UI/Adornment/RenameFlyoutViewModel.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,7 @@ protected virtual void Dispose(bool disposing)
325325
Session.ReplacementsComputed -= OnReplacementsComputed;
326326
Session.CommitStateChange -= CommitStateChange;
327327

328-
if (SmartRenameViewModel is not null)
329-
{
330-
SmartRenameViewModel.Dispose();
331-
}
328+
SmartRenameViewModel?.Dispose();
332329

333330
UnregisterOleComponent();
334331
}

src/EditorFeatures/Core/Shared/Utilities/CaretPreservingEditTransaction.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ public IMergeTextUndoTransactionPolicy? MergePolicy
9393

9494
set
9595
{
96-
if (_transaction != null)
97-
{
98-
_transaction.MergePolicy = value;
99-
}
96+
_transaction?.MergePolicy = value;
10097
}
10198
}
10299

src/EditorFeatures/Core/SignatureHelp/Presentation/SignatureHelpPresenter.SignatureHelpPresenterSession.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ public void PresentItems(
9797
Contract.ThrowIfNull(_signatureMap);
9898

9999
var defaultValue = _signatureMap.GetValueOrDefault(_selectedItem);
100-
if (_editorSessionOpt != null)
101-
{
102-
_editorSessionOpt.SelectedSignature = defaultValue;
103-
}
100+
_editorSessionOpt?.SelectedSignature = defaultValue;
104101
}
105102
finally
106103
{

src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionTest.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ internal static void EnableOptions(
166166
internal static void EnableOption(ImmutableArray<PickMembersOption> options, string id)
167167
{
168168
var option = options.FirstOrDefault(o => o.Id == id);
169-
if (option != null)
170-
{
171-
option.Value = true;
172-
}
169+
option?.Value = true;
173170
}
174171

175172
internal Task TestWithPickMembersDialogAsync(

src/Features/Core/Portable/GenerateOverrides/GenerateOverridesWithDialogCodeAction.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ private sealed class ChangeOptionValueOperation(bool selectedAll) : CodeActionOp
102102
public override void Apply(Workspace workspace, CancellationToken cancellationToken)
103103
{
104104
var service = workspace.Services.GetService<ILegacyGlobalOptionsWorkspaceService>();
105-
if (service != null)
106-
{
107-
service.GenerateOverrides = _selectedAll;
108-
}
105+
service?.GenerateOverrides = _selectedAll;
109106
}
110107
}
111108
}

src/Features/Core/Portable/QuickInfo/QuickInfoUtilities.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ public static async Task<QuickInfoItem> CreateQuickInfoItemAsync(
7777
if (groups.TryGetValue(SymbolDescriptionGroups.Documentation, out var docParts) && !docParts.IsDefaultOrEmpty)
7878
{
7979
AddSection(QuickInfoSectionKinds.DocumentationComments, docParts);
80-
if (onTheFlyDocsInfo != null)
81-
{
82-
onTheFlyDocsInfo.HasComments = true;
83-
}
80+
onTheFlyDocsInfo?.HasComments = true;
8481
}
8582

8683
if (options.QuickInfoOptions.ShowRemarksInQuickInfo &&

src/Features/DiagnosticsTestUtilities/CodeActionsLegacy/AbstractCodeActionTest_NoEditor.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,7 @@ internal static void EnableOptions(
174174
internal static void EnableOption(ImmutableArray<PickMembersOption> options, string id)
175175
{
176176
var option = options.FirstOrDefault(o => o.Id == id);
177-
if (option != null)
178-
{
179-
option.Value = true;
180-
}
177+
option?.Value = true;
181178
}
182179

183180
internal Task TestWithPickMembersDialogAsync(

src/Scripting/Core/ScriptBuilder.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,7 @@ private Func<object[], Task<T>> Build<T>(
152152

153153
peStream.Position = 0;
154154

155-
if (pdbStreamOpt != null)
156-
{
157-
pdbStreamOpt.Position = 0;
158-
}
155+
pdbStreamOpt?.Position = 0;
159156

160157
var assembly = _assemblyLoader.LoadAssemblyFromStream(peStream, pdbStreamOpt);
161158
var runtimeEntryPoint = GetEntryPointRuntimeMethod(entryPoint, assembly);

0 commit comments

Comments
 (0)