Skip to content

Commit

Permalink
Replace Tuple with ValueTuple (gitextensions#4734)
Browse files Browse the repository at this point in the history
* Replace DeconstructionExtensions Tuple methods with System.ValueTuple
* Replace usages of Tuple with ValueTuple
* Remove redundant using directives
  • Loading branch information
drewnoakes authored and RussKie committed Mar 29, 2018
1 parent c44c724 commit d22a21a
Show file tree
Hide file tree
Showing 34 changed files with 78 additions and 107 deletions.
27 changes: 0 additions & 27 deletions GitCommands/DeconstructionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,5 @@ public static void Deconstruct<TKey, TElement>(this IGrouping<TKey, TElement> so
key = source.Key;
elements = source;
}

/// <summary>
/// Supports C# 7 deconstruction of <see cref="Tuple{T1}"/>.
/// </summary>
public static void Deconstruct<T1>(this Tuple<T1> source, out T1 item1)
{
item1 = source.Item1;
}

/// <summary>
/// Supports C# 7 deconstruction of <see cref="Tuple{T1,T2}"/>.
/// </summary>
public static void Deconstruct<T1, T2>(this Tuple<T1, T2> source, out T1 item1, out T2 item2)
{
item1 = source.Item1;
item2 = source.Item2;
}

/// <summary>
/// Supports C# 7 deconstruction of <see cref="Tuple{T1,T2,T3}"/>.
/// </summary>
public static void Deconstruct<T1, T2, T3>(this Tuple<T1, T2, T3> source, out T1 item1, out T2 item2, out T3 item3)
{
item1 = source.Item1;
item2 = source.Item2;
item3 = source.Item3;
}
}
}
2 changes: 0 additions & 2 deletions GitCommands/Git/EnvironmentConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using GitCommands.Utils;
using JetBrains.Annotations;

Expand Down
1 change: 0 additions & 1 deletion GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using GitCommands.Config;
using GitCommands.Git;
Expand Down
3 changes: 3 additions & 0 deletions GitCommands/GitCommands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
Expand Down
4 changes: 2 additions & 2 deletions GitCommands/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ public static bool IsPortable()
return Properties.Settings.Default.IsPortable;
}

private static IEnumerable<Tuple<string, string>> GetSettingsFromRegistry()
private static IEnumerable<(string name, string value)> GetSettingsFromRegistry()
{
RegistryKey oldSettings = VersionIndependentRegKey.OpenSubKey("GitExtensions");

Expand All @@ -1511,7 +1511,7 @@ private static IEnumerable<Tuple<string, string>> GetSettingsFromRegistry()

if (value != null)
{
yield return Tuple.Create(name, value.ToString());
yield return (name, value.ToString());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion GitCommands/Settings/SettingsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Load()
});
}

public void Import(IEnumerable<Tuple<string, string>> keyValuePairs)
public void Import(IEnumerable<(string name, string value)> keyValuePairs)
{
LockedAction(() =>
{
Expand Down
12 changes: 7 additions & 5 deletions GitCommands/Statistics/CommitCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ namespace GitCommands.Statistics
{
public static class CommitCounter
{
public static Tuple<Dictionary<string, int>, int> GroupAllCommitsByContributor(IGitModule module)
public static (Dictionary<string, int> commitsPerContributor, int totalCommits)
GroupAllCommitsByContributor(IGitModule module)
{
return GroupAllCommitsByContributor(module, DateTime.MinValue, DateTime.MaxValue);
}

private static Tuple<Dictionary<string, int>, int> GroupAllCommitsByContributor(IGitModule module, DateTime since, DateTime until)
private static (Dictionary<string, int> commitsPerContributor, int totalCommits)
GroupAllCommitsByContributor(IGitModule module, DateTime since, DateTime until)
{
var sinceParam = since != DateTime.MinValue ? GetDateParameter(since, "since") : "";
var untilParam = until != DateTime.MaxValue ? GetDateParameter(since, "until") : "";
Expand All @@ -24,8 +26,8 @@ private static Tuple<Dictionary<string, int>, int> GroupAllCommitsByContributor(
return ParseCommitsPerContributor(unformattedCommitsPerContributor);
}

private static Tuple<Dictionary<string, int>, int> ParseCommitsPerContributor(
IEnumerable<string> unformattedCommitsPerContributor)
private static (Dictionary<string, int> commitsPerContributor, int totalCommits)
ParseCommitsPerContributor(IEnumerable<string> unformattedCommitsPerContributor)
{
var commitsPerContributor = new Dictionary<string, int>();
var delimiter = new[] { ' ', '\t' };
Expand Down Expand Up @@ -62,7 +64,7 @@ private static Tuple<Dictionary<string, int>, int> ParseCommitsPerContributor(
}
}

return Tuple.Create(commitsPerContributor, totalCommits);
return (commitsPerContributor, totalCommits);
}

private static string GetDateParameter(DateTime sinceDate, string paramName)
Expand Down
1 change: 1 addition & 0 deletions GitCommands/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<package id="SmartFormat.NET" version="2.0.0.0" targetFramework="net461" />
<package id="StyleCop.Analyzers" version="1.1.0-beta006" targetFramework="net461" developmentDependency="true" />
<package id="System.IO.Abstractions" version="2.0.0.144" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
</packages>
1 change: 0 additions & 1 deletion GitExtUtils/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: InternalsVisibleTo("GitExtensions")]
[assembly: InternalsVisibleTo("CommonTestUtils")]
2 changes: 0 additions & 2 deletions GitExtensions/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Configuration;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitCommands;
using GitCommands.Utils;
Expand Down
1 change: 0 additions & 1 deletion GitUI/CommandsDialogs/BrowseDialog/FormBisect.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using GitCommands;
Expand Down
4 changes: 2 additions & 2 deletions GitUI/CommandsDialogs/BrowseDialog/FormBrowseMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ private void CreateAdditionalMainMenuItems()
}
}

private IEnumerable<Tuple<string, object>> GetAdditionalMainMenuItemsForTranslation()
private IEnumerable<(string name, object item)> GetAdditionalMainMenuItemsForTranslation()
{
var list = new[] { _navigateToolStripMenuItem, _viewToolStripMenuItem };
return list.Select(menuItem => Tuple.Create(menuItem.Name, (object)menuItem));
return list.Select(menuItem => (menuItem.Name, (object)menuItem));
}

private void SetDropDownItems(ToolStripMenuItem toolStripMenuItemTarget, IEnumerable<MenuCommand> menuCommands)
Expand Down
1 change: 0 additions & 1 deletion GitUI/CommandsDialogs/BrowseDialog/MenuCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

namespace GitUI.CommandsDialogs.BrowseDialog
Expand Down
7 changes: 3 additions & 4 deletions GitUI/CommandsDialogs/BrowseDialog/MenuCommandsBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using GitCommands;
using ResourceManager;
Expand Down Expand Up @@ -31,9 +30,9 @@ public virtual void TranslateItems(ITranslation translation)
// override and return all commands created by extending class
protected abstract IEnumerable<MenuCommand> GetMenuCommandsForTranslation();

private IEnumerable<Tuple<string, object>> GetMenuCommandsForTranslationImpl()
private IEnumerable<(string name, object item)> GetMenuCommandsForTranslationImpl()
{
return GetMenuCommandsForTranslation().Select(menu => Tuple.Create(menu.Name, (object)menu));
return GetMenuCommandsForTranslation().Select(menu => (menu.Name, (object)menu));
}
}
}
2 changes: 0 additions & 2 deletions GitUI/CommandsDialogs/BuildReportTabPageExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitCommands;
using GitUI.UserControls;
using Microsoft.VisualStudio.Threading;

namespace GitUI.CommandsDialogs
{
Expand Down
1 change: 0 additions & 1 deletion GitUI/CommandsDialogs/FormLog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Windows.Forms;
using GitCommands;

namespace GitUI.CommandsDialogs
Expand Down
1 change: 0 additions & 1 deletion GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitCommands;
using GitUIPluginInterfaces;
Expand Down
3 changes: 3 additions & 0 deletions GitUI/GitUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
<Private>True</Private>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
Expand Down
1 change: 0 additions & 1 deletion GitUI/GitUIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitCommands;
Expand Down
1 change: 1 addition & 0 deletions GitUI/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<package id="System.Reactive.Interfaces" version="3.1.1" targetFramework="net461" />
<package id="System.Reactive.Linq" version="3.1.1" targetFramework="net461" />
<package id="System.Reactive.PlatformServices" version="3.1.1" targetFramework="net461" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
</packages>
1 change: 0 additions & 1 deletion Plugins/Statistics/GitImpact/FormImpact.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading;
using System.Windows.Forms;
using GitCommands.Statistics;
using GitUI;
Expand Down
3 changes: 3 additions & 0 deletions Plugins/Statistics/GitImpact/GitImpact.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>
Expand Down
39 changes: 19 additions & 20 deletions Plugins/Statistics/GitImpact/ImpactControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class ImpactControl : UserControl
private Dictionary<string, SolidBrush> _brushes;

// The changed-lines-labels for each author
private Dictionary<string, List<Tuple<PointF, int>>> _lineLabels;
private Dictionary<string, List<(PointF point, int size)>> _lineLabels;

// The week-labels
private List<Tuple<PointF, DateTime>> _weekLabels;
private List<(PointF point, DateTime date)> _weekLabels;

private HScrollBar _scrollBar;

Expand Down Expand Up @@ -79,8 +79,8 @@ private void Clear()
_authorStack = new List<string>();
_paths = new Dictionary<string, GraphicsPath>();
_brushes = new Dictionary<string, SolidBrush>();
_lineLabels = new Dictionary<string, List<Tuple<PointF, int>>>();
_weekLabels = new List<Tuple<PointF, DateTime>>();
_lineLabels = new Dictionary<string, List<(PointF, int)>>();
_weekLabels = new List<(PointF, DateTime)>();
}
}

Expand Down Expand Up @@ -305,11 +305,11 @@ private void DrawWeekLabels(Graphics g)
{
Brush brush = Brushes.Gray;

foreach (var (point, size) in _weekLabels)
foreach (var (point, date) in _weekLabels)
{
SizeF sz = g.MeasureString(size.ToString("dd. MMM yy"), font);
SizeF sz = g.MeasureString(date.ToString("dd. MMM yy"), font);
PointF pt = new PointF(point.X - (sz.Width / 2), point.Y + (sz.Height / 2));
g.DrawString(size.ToString("dd. MMM yy"), font, brush, pt);
g.DrawString(date.ToString("dd. MMM yy"), font, brush, pt);
}
}
}
Expand All @@ -326,7 +326,7 @@ private void UpdatePathsAndLabels()
{
int h_max = 0;
int x = 0;
var author_points_dict = new Dictionary<string, List<Tuple<Rectangle, int>>>();
var author_points_dict = new Dictionary<string, List<(Rectangle, int changeCount)>>();

lock (_dataLock)
{
Expand All @@ -348,10 +348,10 @@ private void UpdatePathsAndLabels()
// Add rectangle to temporary list
if (!author_points_dict.ContainsKey(author))
{
author_points_dict.Add(author, new List<Tuple<Rectangle, int>>());
author_points_dict.Add(author, new List<(Rectangle, int)>());
}

author_points_dict[author].Add(Tuple.Create(rc, data.ChangedLines));
author_points_dict[author].Add((rc, data.ChangedLines));

// Create a new random brush for the author if none exists yet
if (!_brushes.ContainsKey(author))
Expand All @@ -368,7 +368,7 @@ private void UpdatePathsAndLabels()
h_max = Math.Max(h_max, y);

// Add week date label
_weekLabels.Add(Tuple.Create(new PointF(x + (BlockWidth / 2), y), weekDate));
_weekLabels.Add((new PointF(x + (BlockWidth / 2), y), weekDate));

// Increase x for next week
x += BlockWidth + TransitionWidth;
Expand All @@ -382,9 +382,9 @@ private void UpdatePathsAndLabels()
{
var (point, date) = _weekLabels[i];

_weekLabels[i] = Tuple.Create(
new PointF(point.X, point.Y * (float)height_factor),
date);
var adjustedPoint = new PointF(point.X, point.Y * (float)height_factor);

_weekLabels[i] = (adjustedPoint, date);
}

// Clear previous paths
Expand All @@ -404,20 +404,19 @@ private void UpdatePathsAndLabels()
var rect = new Rectangle(unscaledRect.Left, (int)(unscaledRect.Top * height_factor),
unscaledRect.Width, Math.Max(1, (int)(unscaledRect.Height * height_factor)));

points[i] = Tuple.Create(rect, num);
points[i] = (rect, num);

// Add lines-changed-labels
if (!_lineLabels.ContainsKey(author))
{
_lineLabels.Add(author, new List<Tuple<PointF, int>>());
_lineLabels.Add(author, new List<(PointF, int)>());
}

if (rect.Height > LinesFontSize * 1.5)
{
_lineLabels[author].Add(
Tuple.Create(
new PointF(rect.Left + (BlockWidth / 2), rect.Top + (rect.Height / 2)),
num));
var adjustedPoint = new PointF(rect.Left + (BlockWidth / 2), rect.Top + (rect.Height / 2));

_lineLabels[author].Add((adjustedPoint, num));
}
}

Expand Down
1 change: 1 addition & 0 deletions Plugins/Statistics/GitImpact/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<package id="Microsoft.VisualStudio.Threading.Analyzers" version="15.6.46" targetFramework="net461" />
<package id="Microsoft.VisualStudio.Validation" version="15.3.15" targetFramework="net461" />
<package id="StyleCop.Analyzers" version="1.1.0-beta006" targetFramework="net461" developmentDependency="true" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
</packages>
1 change: 0 additions & 1 deletion Plugins/Statistics/GitStatistics/FormGitStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitCommands;
Expand Down
3 changes: 3 additions & 0 deletions Plugins/Statistics/GitStatistics/GitStatistics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>
Expand Down
Loading

0 comments on commit d22a21a

Please sign in to comment.