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

Commit 56b36e5

Browse files
committed
Use expression bodies wherever possible
Also we should prefer to use `var` unless the type's really not clear at all from the right hand side. Also, I prefer all the usings on top and not within namespaces.
1 parent 4fb1bc6 commit 56b36e5

File tree

4 files changed

+36
-63
lines changed

4 files changed

+36
-63
lines changed

src/GitHub.Exports/Extensions/SimpleRepositoryModelExtensions.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
using GitHub.Models;
2-
using System;
1+
using System;
32
using System.Linq;
43
using System.IO;
4+
using GitHub.Models;
55
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
66

77
namespace GitHub.Extensions
88
{
9-
using Services;
10-
using VisualStudio;
119
public static class SimpleRepositoryModelExtensions
1210
{
1311
/// <summary>
1412
/// Create a SimpleRepositoryModel from a VS git repo object
1513
/// </summary>
1614
public static ISimpleRepositoryModel ToModel(this IGitRepositoryInfo repo)
1715
{
18-
if (repo == null)
19-
return null;
20-
return new SimpleRepositoryModel(repo.RepositoryPath);
16+
return repo == null ? null : new SimpleRepositoryModel(repo.RepositoryPath);
2117
}
2218

2319
public static bool HasCommits(this ISimpleRepositoryModel repository)
2420
{
25-
var repo = Services.IGitService.GetRepo(repository.LocalPath);
21+
var repo = VisualStudio.Services.IGitService.GetRepo(repository.LocalPath);
2622
return repo?.Commits.Any() ?? false;
2723
}
2824

src/GitHub.Exports/Extensions/VSExtensions.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using GitHub.Services;
2-
using Microsoft.TeamFoundation.Controls;
3-
using System;
1+
using System;
42
using System.Diagnostics;
3+
using GitHub.Services;
4+
using Microsoft.TeamFoundation.Controls;
55

66
namespace GitHub.Extensions
77
{
8-
using VisualStudio;
9-
108
public static class VSExtensions
119
{
1210
public static T TryGetService<T>(this IServiceProvider serviceProvider) where T : class
@@ -41,9 +39,9 @@ public static T GetService<T>(this IServiceProvider serviceProvider)
4139
public static T GetExportedValue<T>(this IServiceProvider serviceProvider)
4240
{
4341
var ui = serviceProvider as IUIProvider;
44-
if (ui != null)
45-
return ui.GetService<T>();
46-
return Services.ComponentModel.DefaultExportProvider.GetExportedValue<T>();
42+
return ui != null
43+
? ui.GetService<T>()
44+
: VisualStudio.Services.ComponentModel.DefaultExportProvider.GetExportedValue<T>();
4745
}
4846

4947
public static ITeamExplorerSection GetSection(this IServiceProvider serviceProvider, Guid section)

src/GitHub.Exports/Models/SimpleRepositoryModel.cs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
using GitHub.Extensions;
2-
using GitHub.Primitives;
3-
using GitHub.Services;
4-
using GitHub.UI;
5-
using GitHub.VisualStudio;
6-
using GitHub.VisualStudio.Helpers;
7-
using System;
1+
using System;
82
using System.Diagnostics;
93
using System.Globalization;
104
using System.IO;
5+
using GitHub.Primitives;
6+
using GitHub.UI;
7+
using GitHub.VisualStudio.Helpers;
118

129
namespace GitHub.Models
1310
{
14-
using VisualStudio;
15-
1611
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1712
public class SimpleRepositoryModel : NotificationAwareObject, ISimpleRepositoryModel, INotifyPropertySource, IEquatable<SimpleRepositoryModel>
1813
{
@@ -31,10 +26,8 @@ public SimpleRepositoryModel(string path)
3126
var dir = new DirectoryInfo(path);
3227
if (!dir.Exists)
3328
throw new ArgumentException("Path does not exist", nameof(path));
34-
var uri = Services.IGitService.GetUri(path);
35-
var name = uri?.NameWithOwner;
36-
if (name == null)
37-
name = dir.Name;
29+
var uri = VisualStudio.Services.IGitService.GetUri(path);
30+
var name = uri?.NameWithOwner ?? dir.Name;
3831
Name = name;
3932
LocalPath = path;
4033
CloneUrl = uri;
@@ -54,15 +47,15 @@ public void Refresh()
5447
{
5548
if (LocalPath == null)
5649
return;
57-
var uri = Services.IGitService.GetUri(LocalPath);
50+
var uri = VisualStudio.Services.IGitService.GetUri(LocalPath);
5851
if (CloneUrl != uri)
5952
CloneUrl = uri;
6053
}
6154

62-
public string Name { get; private set; }
55+
public string Name { get; }
6356
UriString cloneUrl;
6457
public UriString CloneUrl { get { return cloneUrl; } set { cloneUrl = value; this.RaisePropertyChange(); } }
65-
public string LocalPath { get; private set; }
58+
public string LocalPath { get; }
6659
Octicon icon;
6760
public Octicon Icon { get { return icon; } set { icon = value; this.RaisePropertyChange(); } }
6861

@@ -91,13 +84,12 @@ bool IEquatable<SimpleRepositoryModel>.Equals(SimpleRepositoryModel other)
9184
return other != null && String.Equals(Name, other.Name) && String.Equals(CloneUrl, other.CloneUrl) && String.Equals(LocalPath?.TrimEnd('\\'), other.LocalPath?.TrimEnd('\\'), StringComparison.CurrentCultureIgnoreCase);
9285
}
9386

94-
internal string DebuggerDisplay
95-
{
96-
get
97-
{
98-
return String.Format(CultureInfo.InvariantCulture,
99-
"{3}\tName: {0} CloneUrl: {1} LocalPath: {2}", Name, CloneUrl, LocalPath, GetHashCode());
100-
}
101-
}
87+
internal string DebuggerDisplay => String.Format(
88+
CultureInfo.InvariantCulture,
89+
"{3}\tName: {0} CloneUrl: {1} LocalPath: {2}",
90+
Name,
91+
CloneUrl,
92+
LocalPath,
93+
GetHashCode());
10294
}
10395
}

src/GitHub.Exports/Services/Services.cs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
using System;
22
using EnvDTE;
33
using EnvDTE80;
4+
using GitHub.Extensions;
5+
using GitHub.Info;
6+
using GitHub.Primitives;
47
using GitHub.Services;
58
using LibGit2Sharp;
69
using Microsoft.VisualStudio;
710
using Microsoft.VisualStudio.ComponentModelHost;
811
using Microsoft.VisualStudio.Shell.Interop;
9-
using GitHub.Info;
10-
using GitHub.Primitives;
11-
using GitHub.Extensions;
1212

1313
namespace GitHub.VisualStudio
1414
{
15-
1615
public static class Services
1716
{
1817
public static IServiceProvider PackageServiceProvider { get; set; }
@@ -37,20 +36,14 @@ static Ret GetGlobalService<T, Ret>(IServiceProvider provider = null) where T :
3736
return PackageServiceProvider.GetService(typeof(T)) as Ret;
3837
}
3938

40-
public static IComponentModel ComponentModel
41-
{
42-
get { return GetGlobalService<SComponentModel, IComponentModel>(); }
43-
}
39+
public static IComponentModel ComponentModel => GetGlobalService<SComponentModel, IComponentModel>();
4440

4541
public static IVsWebBrowsingService GetWebBrowsingService(this IServiceProvider provider)
4642
{
4743
return GetGlobalService<SVsWebBrowsingService, IVsWebBrowsingService>(provider);
4844
}
4945

50-
public static IVsOutputWindow OutputWindow
51-
{
52-
get { return GetGlobalService<SVsOutputWindow, IVsOutputWindow>(); }
53-
}
46+
public static IVsOutputWindow OutputWindow => GetGlobalService<SVsOutputWindow, IVsOutputWindow>();
5447

5548
static IVsOutputWindowPane outputWindowPane = null;
5649
public static IVsOutputWindowPane OutputWindowPane
@@ -62,14 +55,14 @@ public static IVsOutputWindowPane OutputWindowPane
6255
// First make sure the output window is visible
6356
var uiShell = GetGlobalService<SVsUIShell, IVsUIShell>();
6457
// Get the frame of the output window
65-
Guid outputWindowGuid = new Guid("{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}");
58+
var outputWindowGuid = new Guid("{34e76e81-ee4a-11d0-ae2e-00a0c90fffc3}");
6659
IVsWindowFrame outputWindowFrame = null;
6760
ErrorHandler.ThrowOnFailure(uiShell.FindToolWindow((uint)__VSCREATETOOLWIN.CTW_fForceCreate, ref outputWindowGuid, out outputWindowFrame));
6861
// Show the output window
6962
if (outputWindowFrame != null)
7063
ErrorHandler.ThrowOnFailure(outputWindowFrame.Show());
7164

72-
Guid paneGuid = new Guid("E37A42B1-C1AE-475C-9982-7F49FE61918D");
65+
var paneGuid = new Guid("E37A42B1-C1AE-475C-9982-7F49FE61918D");
7366
ErrorHandler.ThrowOnFailure(OutputWindow.CreatePane(ref paneGuid, ApplicationInfo.ApplicationSafeName, 1 /*visible=true*/, 0 /*clearWithSolution=false*/));
7467
ErrorHandler.ThrowOnFailure(OutputWindow.GetPane(ref paneGuid, out outputWindowPane));
7568
}
@@ -78,15 +71,9 @@ public static IVsOutputWindowPane OutputWindowPane
7871
}
7972
}
8073

81-
public static DTE Dte
82-
{
83-
get { return GetGlobalService<DTE, DTE>(); }
84-
}
74+
public static DTE Dte => GetGlobalService<DTE, DTE>();
8575

86-
public static DTE2 Dte2
87-
{
88-
get { return Dte as DTE2; }
89-
}
76+
public static DTE2 Dte2 => Dte as DTE2;
9077

9178
public static IVsActivityLog GetActivityLog(this IServiceProvider provider)
9279
{
@@ -130,6 +117,6 @@ static UriString GetUri(IRepository repo)
130117
{
131118
return UriString.ToUriString(GitService.GetUriFromRepository(repo)?.ToRepositoryUrl());
132119
}
133-
public static IGitService IGitService { get { return PackageServiceProvider.GetService<IGitService>(); } }
120+
public static IGitService IGitService => PackageServiceProvider.GetService<IGitService>();
134121
}
135122
}

0 commit comments

Comments
 (0)