Skip to content

Commit 9db7919

Browse files
committed
Simplify "if" statements (IDE0045)
1 parent fa5a86b commit 9db7919

11 files changed

+96
-490
lines changed

src/Cake.AzureDevOps/AzureDevOpsAliases.Pipelines.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ public static AzureDevOpsBuild AzureDevOpsBuild(
5050

5151
var build = new AzureDevOpsBuild(context.Log, settings, new BuildClientFactory(), new TestManagementClientFactory(), new WorkItemTrackingClientFactory());
5252

53-
if (build.HasBuildLoaded)
54-
{
55-
return build;
56-
}
57-
58-
return null;
53+
return build.HasBuildLoaded ? build : null;
5954
}
6055

6156
/// <summary>

src/Cake.AzureDevOps/AzureDevOpsAliases.PullRequest.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,7 @@ public static AzureDevOpsPullRequest AzureDevOpsPullRequest(
5252

5353
var pullRequest = new AzureDevOpsPullRequest(context.Log, settings, new GitClientFactory());
5454

55-
if (pullRequest.HasPullRequestLoaded)
56-
{
57-
return pullRequest;
58-
}
59-
60-
return null;
55+
return pullRequest.HasPullRequestLoaded ? pullRequest : null;
6156
}
6257

6358
/// <summary>

src/Cake.AzureDevOps/AzureDevOpsAliases.WorkItemTracking.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ public static AzureDevOpsWorkItem AzureDevOpsWorkItem(
4848

4949
var workItem = new AzureDevOpsWorkItem(context.Log, settings, new WorkItemTrackingClientFactory());
5050

51-
if (workItem.HasWorkItemLoaded)
52-
{
53-
return workItem;
54-
}
55-
56-
return null;
51+
return workItem.HasWorkItemLoaded ? workItem : null;
5752
}
5853

5954
/// <summary>

src/Cake.AzureDevOps/Boards/WorkItemTracking/AzureDevOpsWorkItem.cs

Lines changed: 19 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,7 @@ internal AzureDevOpsWorkItem(
148148
/// </summary>
149149
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
150150
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
151-
public int WorkItemId
152-
{
153-
get
154-
{
155-
if (!this.ValidateWorkItem())
156-
{
157-
return 0;
158-
}
159-
160-
return this.workItem.Id ?? 0;
161-
}
162-
}
151+
public int WorkItemId => this.ValidateWorkItem() ? this.workItem.Id ?? 0 : 0;
163152

164153
/// <summary>
165154
/// Gets the title of the work item.
@@ -168,18 +157,7 @@ public int WorkItemId
168157
/// </summary>
169158
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
170159
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
171-
public string Title
172-
{
173-
get
174-
{
175-
if (!this.ValidateWorkItem())
176-
{
177-
return string.Empty;
178-
}
179-
180-
return this.GetField("System.Title");
181-
}
182-
}
160+
public string Title => this.ValidateWorkItem() ? this.GetField("System.Title") : string.Empty;
183161

184162
/// <summary>
185163
/// Gets the description of the work item.
@@ -188,18 +166,7 @@ public string Title
188166
/// </summary>
189167
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
190168
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
191-
public string Description
192-
{
193-
get
194-
{
195-
if (!this.ValidateWorkItem())
196-
{
197-
return string.Empty;
198-
}
199-
200-
return this.GetField("System.Description");
201-
}
202-
}
169+
public string Description => this.ValidateWorkItem() ? this.GetField("System.Description") : string.Empty;
203170

204171
/// <summary>
205172
/// Gets the area path of the work item.
@@ -208,18 +175,7 @@ public string Description
208175
/// </summary>
209176
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
210177
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
211-
public string AreaPath
212-
{
213-
get
214-
{
215-
if (!this.ValidateWorkItem())
216-
{
217-
return string.Empty;
218-
}
219-
220-
return this.GetField("System.AreaPath");
221-
}
222-
}
178+
public string AreaPath => this.ValidateWorkItem() ? this.GetField("System.AreaPath") : string.Empty;
223179

224180
/// <summary>
225181
/// Gets the team project name of the work item.
@@ -228,18 +184,7 @@ public string AreaPath
228184
/// </summary>
229185
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
230186
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
231-
public string TeamProject
232-
{
233-
get
234-
{
235-
if (!this.ValidateWorkItem())
236-
{
237-
return string.Empty;
238-
}
239-
240-
return this.GetField("System.TeamProject");
241-
}
242-
}
187+
public string TeamProject => this.ValidateWorkItem() ? this.GetField("System.TeamProject") : string.Empty;
243188

244189
/// <summary>
245190
/// Gets the iteration path of the work item.
@@ -248,18 +193,7 @@ public string TeamProject
248193
/// </summary>
249194
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
250195
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
251-
public string IterationPath
252-
{
253-
get
254-
{
255-
if (!this.ValidateWorkItem())
256-
{
257-
return string.Empty;
258-
}
259-
260-
return this.GetField("System.IterationPath");
261-
}
262-
}
196+
public string IterationPath => this.ValidateWorkItem() ? this.GetField("System.IterationPath") : string.Empty;
263197

264198
/// <summary>
265199
/// Gets the type of the work item.
@@ -268,18 +202,7 @@ public string IterationPath
268202
/// </summary>
269203
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
270204
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
271-
public string WorkItemType
272-
{
273-
get
274-
{
275-
if (!this.ValidateWorkItem())
276-
{
277-
return string.Empty;
278-
}
279-
280-
return this.GetField("System.WorkItemType");
281-
}
282-
}
205+
public string WorkItemType => this.ValidateWorkItem() ? this.GetField("System.WorkItemType") : string.Empty;
283206

284207
/// <summary>
285208
/// Gets the state of the work item.
@@ -288,18 +211,7 @@ public string WorkItemType
288211
/// </summary>
289212
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
290213
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
291-
public string State
292-
{
293-
get
294-
{
295-
if (!this.ValidateWorkItem())
296-
{
297-
return string.Empty;
298-
}
299-
300-
return this.GetField("System.State");
301-
}
302-
}
214+
public string State => this.ValidateWorkItem() ? this.GetField("System.State") : string.Empty;
303215

304216
/// <summary>
305217
/// Gets the reason of the state of the work item.
@@ -308,18 +220,7 @@ public string State
308220
/// </summary>
309221
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
310222
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
311-
public string Reason
312-
{
313-
get
314-
{
315-
if (!this.ValidateWorkItem())
316-
{
317-
return string.Empty;
318-
}
319-
320-
return this.GetField("System.Reason");
321-
}
322-
}
223+
public string Reason => this.ValidateWorkItem() ? this.GetField("System.Reason") : string.Empty;
323224

324225
/// <summary>
325226
/// Gets the create date of the work item.
@@ -328,18 +229,7 @@ public string Reason
328229
/// </summary>
329230
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
330231
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
331-
public DateTime CreateDate
332-
{
333-
get
334-
{
335-
if (!this.ValidateWorkItem())
336-
{
337-
return DateTime.MinValue;
338-
}
339-
340-
return this.GetFieldAsDate("System.CreatedDate");
341-
}
342-
}
232+
public DateTime CreateDate => this.ValidateWorkItem() ? this.GetFieldAsDate("System.CreatedDate") : DateTime.MinValue;
343233

344234
/// <summary>
345235
/// Gets the modify date of the work item.
@@ -348,18 +238,7 @@ public DateTime CreateDate
348238
/// </summary>
349239
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
350240
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
351-
public DateTime ChangeDate
352-
{
353-
get
354-
{
355-
if (!this.ValidateWorkItem())
356-
{
357-
return DateTime.MinValue;
358-
}
359-
360-
return this.GetFieldAsDate("System.ChangedDate");
361-
}
362-
}
241+
public DateTime ChangeDate => this.ValidateWorkItem() ? this.GetFieldAsDate("System.ChangedDate") : DateTime.MinValue;
363242

364243
/// <summary>
365244
/// Gets the tags of the work item.
@@ -368,18 +247,9 @@ public DateTime ChangeDate
368247
/// </summary>
369248
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
370249
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
371-
public IEnumerable<string> Tags
372-
{
373-
get
374-
{
375-
if (!this.ValidateWorkItem())
376-
{
377-
return Array.Empty<string>();
378-
}
379-
380-
return this.GetField("System.Tags").Split("; ", StringSplitOptions.RemoveEmptyEntries);
381-
}
382-
}
250+
public IEnumerable<string> Tags => this.ValidateWorkItem()
251+
? (IEnumerable<string>)this.GetField("System.Tags").Split("; ", StringSplitOptions.RemoveEmptyEntries)
252+
: Array.Empty<string>();
383253

384254
/// <summary>
385255
/// Gets the id of the parent work item.
@@ -388,18 +258,7 @@ public IEnumerable<string> Tags
388258
/// </summary>
389259
/// <exception cref="AzureDevOpsWorkItemNotFoundException">If work item could not be found and
390260
/// <see cref="AzureDevOpsWorkItemSettings.ThrowExceptionIfWorkItemCouldNotBeFound"/> is set to <c>true</c>.</exception>
391-
public int ParentWorkItemId
392-
{
393-
get
394-
{
395-
if (!this.ValidateWorkItem())
396-
{
397-
return 0;
398-
}
399-
400-
return this.GetFieldAsInt("System.Parent");
401-
}
402-
}
261+
public int ParentWorkItemId => this.ValidateWorkItem() ? this.GetFieldAsInt("System.Parent") : 0;
403262

404263
/// <summary>
405264
/// Gets the parent work item or null of no parent exists.
@@ -445,38 +304,17 @@ private bool ValidateWorkItem()
445304

446305
private string GetField(string fieldName)
447306
{
448-
if (this.workItem.Fields.TryGetValue(fieldName, out var field))
449-
{
450-
return field.ToString();
451-
}
452-
else
453-
{
454-
return string.Empty;
455-
}
307+
return this.workItem.Fields.TryGetValue(fieldName, out var field) ? field.ToString() : string.Empty;
456308
}
457309

458310
private DateTime GetFieldAsDate(string fieldName)
459311
{
460-
if (this.workItem.Fields.TryGetValue(fieldName, out var field))
461-
{
462-
return (DateTime)field;
463-
}
464-
else
465-
{
466-
return DateTime.MinValue;
467-
}
312+
return this.workItem.Fields.TryGetValue(fieldName, out var field) ? (DateTime)field : DateTime.MinValue;
468313
}
469314

470315
private int GetFieldAsInt(string fieldName)
471316
{
472-
if (this.workItem.Fields.TryGetValue(fieldName, out var field))
473-
{
474-
return Convert.ToInt32(field);
475-
}
476-
else
477-
{
478-
return 0;
479-
}
317+
return this.workItem.Fields.TryGetValue(fieldName, out var field) ? Convert.ToInt32(field) : 0;
480318
}
481319
}
482-
}
320+
}

0 commit comments

Comments
 (0)