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

Commit 03e17bc

Browse files
committed
Optimize the Converters
1 parent 2124eb1 commit 03e17bc

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/GitHub.VisualStudio/UI/Views/GitHubConnectContent.xaml.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,11 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
7474
if (values.Length != 2 || parameter as string != "FormatRepositoryName")
7575
return String.Empty;
7676

77-
if (!(values[1] is IGitHubConnectSection))
78-
{
79-
if (values[0] is ISimpleRepositoryModel)
80-
return ((ISimpleRepositoryModel)values[0]).Name;
81-
return String.Empty;
82-
}
83-
84-
var item = (ISimpleRepositoryModel)values[0];
85-
var context = (IGitHubConnectSection)values[1];
77+
var item = values[0] as ISimpleRepositoryModel;
78+
var context = values[1] as IGitHubConnectSection;
79+
if (context == null)
80+
return item?.Name ?? String.Empty;
81+
8682
if (context.SectionConnection.Username == item.CloneUrl.Owner)
8783
return item.CloneUrl.RepositoryName;
8884
return item.Name;
@@ -98,12 +94,12 @@ public class IsCurrentRepositoryConverter : IMultiValueConverter
9894
{
9995
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
10096
{
101-
if (values.Length != 2 || parameter as string != "IsCurrentRepository" || !(values[0] is ISimpleRepositoryModel) || !(values[1] is IGitAwareItem))
97+
if (values.Length != 2 || parameter as string != "IsCurrentRepository")
10298
return false;
10399

104-
var item = (ISimpleRepositoryModel)values[0];
105-
var context = (IGitAwareItem)values[1];
106-
return context.ActiveRepoUri == item.CloneUrl;
100+
var item = values[0] as ISimpleRepositoryModel;
101+
var context = values[1] as IGitAwareItem;
102+
return item != null && context != null && context.ActiveRepoUri == item.CloneUrl;
107103
}
108104

109105
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

0 commit comments

Comments
 (0)