Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit c04ed09

Browse files
committed
🎨 Some nitpicks and cleanup
For the ExportMetadata, the assert didn't cover the potential nullref case, so I refactored it so it would.
1 parent 5bcc9f4 commit c04ed09

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

src/GitHub.Exports/Exports/ExportMetadata.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Windows.Controls;
66
using System.Linq;
77
using System.Diagnostics;
8+
using System.Reflection;
89

910
namespace GitHub.Exports {
1011

@@ -50,8 +51,14 @@ public static class ExportViewAttributeExtensions
5051
{
5152
public static bool IsViewType(this UserControl c, UIViewType type)
5253
{
53-
Debug.Assert(c.GetType().GetCustomAttributesData().Any(x => x.AttributeType == typeof(ExportViewAttribute) && x.NamedArguments.Any() && x.NamedArguments[0].TypedValue.ArgumentType == typeof(UIViewType)), "Someone broke the ExportViewAttribute contract...");
54-
return c.GetType().GetCustomAttributesData().Any(x => x.AttributeType == typeof(ExportViewAttribute) && (UIViewType)x.NamedArguments[0].TypedValue.Value == type);
54+
return c.GetType().GetCustomAttributesData().Any(attr => IsViewType(attr, type));
55+
}
56+
57+
private static bool IsViewType(CustomAttributeData attributeData, UIViewType viewType)
58+
{
59+
Debug.Assert(attributeData.NamedArguments != null);
60+
return attributeData.AttributeType == typeof(ExportViewAttribute)
61+
&& (UIViewType)attributeData.NamedArguments[0].TypedValue.Value == viewType;
5562
}
5663
}
5764
}

src/GitHub.Exports/Services/VSServices.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
using Microsoft.TeamFoundation.Git.Controls.Extensibility;
2-
using System;
1+
using System;
2+
using System.Collections.Generic;
33
using System.ComponentModel.Composition;
44
using System.Globalization;
55
using System.Linq;
6+
using System.Windows.Input;
67
using GitHub.Extensions;
7-
using Microsoft.Win32;
8-
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
8+
using GitHub.Models;
99
using GitHub.VisualStudio;
1010
using Microsoft.TeamFoundation.Controls;
11+
using Microsoft.TeamFoundation.Git.Controls.Extensibility;
1112
using Microsoft.VisualStudio;
1213
using Microsoft.VisualStudio.Shell.Interop;
13-
using System.Collections.Generic;
14-
using GitHub.Models;
15-
using System.Windows.Input;
14+
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
15+
using Microsoft.Win32;
1616

1717
namespace GitHub.Services
1818
{
@@ -181,41 +181,36 @@ public string SetDefaultProjectPath(string path)
181181
public void ShowMessage(string message)
182182
{
183183
var manager = serviceProvider.TryGetService<ITeamExplorer>() as ITeamExplorerNotificationManager;
184-
if (manager != null)
185-
manager.ShowNotification(message, NotificationType.Information, NotificationFlags.None, null, default(Guid));
184+
manager?.ShowNotification(message, NotificationType.Information, NotificationFlags.None, null, default(Guid));
186185
}
187186

188187
public void ShowMessage(string message, ICommand command)
189188
{
190189
var manager = serviceProvider.TryGetService<ITeamExplorer>() as ITeamExplorerNotificationManager;
191-
if (manager != null)
192-
manager.ShowNotification(message, NotificationType.Information, NotificationFlags.None, command, default(Guid));
190+
manager?.ShowNotification(message, NotificationType.Information, NotificationFlags.None, command, default(Guid));
193191
}
194192

195193
public void ShowWarning(string message)
196194
{
197195
var manager = serviceProvider.TryGetService<ITeamExplorer>() as ITeamExplorerNotificationManager;
198-
if (manager != null)
199-
manager.ShowNotification(message, NotificationType.Warning, NotificationFlags.None, null, default(Guid));
196+
manager?.ShowNotification(message, NotificationType.Warning, NotificationFlags.None, null, default(Guid));
200197
}
201198

202199
public void ShowError(string message)
203200
{
204201
var manager = serviceProvider.TryGetService<ITeamExplorer>() as ITeamExplorerNotificationManager;
205-
if (manager != null)
206-
manager.ShowNotification(message, NotificationType.Error, NotificationFlags.None, null, default(Guid));
202+
manager?.ShowNotification(message, NotificationType.Error, NotificationFlags.None, null, default(Guid));
207203
}
208204

209205
public void ClearNotifications()
210206
{
211207
var manager = serviceProvider.TryGetService<ITeamExplorer>() as ITeamExplorerNotificationManager;
212-
if (manager != null)
213-
manager.ClearNotifications();
214-
}
208+
manager?.ClearNotifications();
209+
}
215210

216211
public void ActivityLogMessage(string message)
217212
{
218-
var log = VisualStudio.Services.GetActivityLog(serviceProvider);
213+
var log = serviceProvider.GetActivityLog();
219214
if (log != null)
220215
{
221216
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
@@ -226,7 +221,7 @@ public void ActivityLogMessage(string message)
226221

227222
public void ActivityLogError(string message)
228223
{
229-
var log = VisualStudio.Services.GetActivityLog(serviceProvider);
224+
var log = serviceProvider.GetActivityLog();
230225
if (log != null)
231226
{
232227

@@ -238,7 +233,7 @@ public void ActivityLogError(string message)
238233

239234
public void ActivityLogWarning(string message)
240235
{
241-
var log = VisualStudio.Services.GetActivityLog(serviceProvider);
236+
var log = serviceProvider.GetActivityLog();
242237
if (log != null)
243238
{
244239
if (!ErrorHandler.Succeeded(log.LogEntry((UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_WARNING,

src/GitHub.VisualStudio/TeamExplorer/Connect/GitHubConnectSection.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
using GitHub.Api;
1+
using System;
2+
using System.Collections.Specialized;
3+
using System.ComponentModel;
4+
using System.Globalization;
5+
using System.Linq;
6+
using GitHub.Api;
7+
using GitHub.Exports;
8+
using GitHub.Extensions;
29
using GitHub.Models;
310
using GitHub.Services;
411
using GitHub.UI;
512
using GitHub.VisualStudio.Base;
613
using GitHub.VisualStudio.Helpers;
714
using GitHub.VisualStudio.UI.Views;
815
using Microsoft.TeamFoundation.Controls;
9-
using System.Linq;
10-
using System.Collections.ObjectModel;
11-
using System.Collections.Specialized;
12-
using GitHub.Extensions;
13-
using NullGuard;
16+
using Microsoft.TeamFoundation.MVVM;
1417
using Microsoft.VisualStudio;
15-
using System;
16-
using System.Windows.Data;
17-
using System.ComponentModel;
18+
using NullGuard;
1819
using ReactiveUI;
19-
using GitHub.Exports;
20-
using System.Globalization;
21-
using Microsoft.TeamFoundation.MVVM;
22-
using GitHub.Primitives;
2320

2421
namespace GitHub.VisualStudio.TeamExplorer.Connect
2522
{
@@ -109,10 +106,9 @@ void RefreshConnections(object sender, NotifyCollectionChangedEventArgs e)
109106
Refresh(connectionManager.Connections[sectionIndex]);
110107
break;
111108
case NotifyCollectionChangedAction.Remove:
112-
if (connectionManager.Connections.Count <= sectionIndex)
113-
Refresh(null);
114-
else
115-
Refresh(connectionManager.Connections[sectionIndex]);
109+
Refresh(connectionManager.Connections.Count <= sectionIndex
110+
? null
111+
: connectionManager.Connections[sectionIndex]);
116112
break;
117113
}
118114
}
@@ -176,10 +172,9 @@ public override void Initialize(object sender, SectionInitializeEventArgs e)
176172

177173
void UpdateConnection()
178174
{
179-
if (connectionManager.Connections.Count > sectionIndex)
180-
Refresh(connectionManager.Connections[sectionIndex]);
181-
else
182-
Refresh(SectionConnection);
175+
Refresh(connectionManager.Connections.Count > sectionIndex
176+
? connectionManager.Connections[sectionIndex]
177+
: SectionConnection);
183178
}
184179

185180
void OnPropertyChange(object sender, PropertyChangedEventArgs e)
@@ -246,7 +241,7 @@ void ShowNotification(ISimpleRepositoryModel newrepo, string msg)
246241
vsservices.ClearNotifications();
247242
vsservices.ShowMessage(
248243
msg,
249-
new RelayCommand((o) =>
244+
new RelayCommand(o =>
250245
{
251246
var str = o.ToString();
252247
/* the prefix is the action to perform:

0 commit comments

Comments
 (0)