diff options
author | nulltoken <emeric.fermas@gmail.com> | 2011-11-06 17:01:28 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2011-11-28 18:36:31 +0400 |
commit | 1032a147f341c600a23adbdb493dcb603ad3473e (patch) | |
tree | d8ea7e92bf4665bafc73984a24acdbf759468b59 | |
parent | d526b188d7b18b5d4ed8da4c3e1fb3a1b954e470 (diff) |
Add basic Tuple<T1, T2> type
-rw-r--r-- | LibGit2Sharp.Tests/LazyFixture.cs | 2 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 1 | ||||
-rw-r--r-- | LibGit2Sharp.Tests/TupleFixture.cs | 56 | ||||
-rw-r--r-- | LibGit2Sharp/Branch.cs | 1 | ||||
-rw-r--r-- | LibGit2Sharp/Commit.cs | 1 | ||||
-rw-r--r-- | LibGit2Sharp/Core/Compat/Lazy.cs (renamed from LibGit2Sharp/Core/Lazy.cs) | 2 | ||||
-rw-r--r-- | LibGit2Sharp/Core/Compat/Tuple.cs | 65 | ||||
-rw-r--r-- | LibGit2Sharp/DirectReference.cs | 1 | ||||
-rw-r--r-- | LibGit2Sharp/LibGit2Sharp.csproj | 5 | ||||
-rw-r--r-- | LibGit2Sharp/NamedReference.cs | 1 | ||||
-rw-r--r-- | LibGit2Sharp/Reference.cs | 1 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 1 | ||||
-rw-r--r-- | LibGit2Sharp/TagAnnotation.cs | 1 | ||||
-rwxr-xr-x | LibGit2Sharp/TreeEntry.cs | 1 |
14 files changed, 135 insertions, 4 deletions
diff --git a/LibGit2Sharp.Tests/LazyFixture.cs b/LibGit2Sharp.Tests/LazyFixture.cs index 84862a12..f878b88b 100644 --- a/LibGit2Sharp.Tests/LazyFixture.cs +++ b/LibGit2Sharp.Tests/LazyFixture.cs @@ -1,5 +1,5 @@ using System; -using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; using LibGit2Sharp.Tests.TestHelpers; using NUnit.Framework; diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index df538a91..eaba5a8e 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -64,6 +64,7 @@ <Compile Include="TestHelpers\SignatureExtensions.cs" /> <Compile Include="TestHelpers\TemporaryCloneOfTestRepo.cs" /> <Compile Include="TreeFixture.cs" /> + <Compile Include="TupleFixture.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\LibGit2Sharp\LibGit2Sharp.csproj"> diff --git a/LibGit2Sharp.Tests/TupleFixture.cs b/LibGit2Sharp.Tests/TupleFixture.cs new file mode 100644 index 00000000..f909bcd0 --- /dev/null +++ b/LibGit2Sharp.Tests/TupleFixture.cs @@ -0,0 +1,56 @@ +using LibGit2Sharp.Core.Compat; +using LibGit2Sharp.Tests.TestHelpers; +using NUnit.Framework; + +namespace LibGit2Sharp.Tests +{ + [TestFixture] + public class TupleFixture + { + const int integer = 2; + const string stringy = "hello"; + + private readonly Tuple<int, string> sut = new Tuple<int, string>(integer, stringy); + + [Test] + public void Properties() + { + sut.Item1.ShouldEqual(integer); + sut.Item2.ShouldEqual(stringy); + } + + [Test] + public void GetHashCodeIsTheSame() + { + var sut2 = new Tuple<int, string>(integer, stringy); + + sut.GetHashCode().ShouldEqual(sut2.GetHashCode()); + } + + [Test] + public void GetHashCodeIsDifferent() + { + var sut2 = new Tuple<int, string>(integer + 1, stringy); + + sut.GetHashCode().ShouldNotEqual(sut2.GetHashCode()); + } + + [Test] + public void Equals() + { + var sut2 = new Tuple<int, string>(integer, stringy); + + sut.Equals(sut2).ShouldBeTrue(); + Equals(sut, sut2).ShouldBeTrue(); + } + + [Test] + public void NotEquals() + { + var sut2 = new Tuple<int, string>(integer + 1, stringy); + + sut.Equals(sut2).ShouldBeFalse(); + Equals(sut, sut2).ShouldBeFalse(); + } + } +} diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs index ff1c73c9..745ef60a 100644 --- a/LibGit2Sharp/Branch.cs +++ b/LibGit2Sharp/Branch.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Linq; using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; namespace LibGit2Sharp { diff --git a/LibGit2Sharp/Commit.cs b/LibGit2Sharp/Commit.cs index b35aa366..c5bc5ec6 100644 --- a/LibGit2Sharp/Commit.cs +++ b/LibGit2Sharp/Commit.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; namespace LibGit2Sharp { diff --git a/LibGit2Sharp/Core/Lazy.cs b/LibGit2Sharp/Core/Compat/Lazy.cs index f6bbe0cb..a4eb40d7 100644 --- a/LibGit2Sharp/Core/Lazy.cs +++ b/LibGit2Sharp/Core/Compat/Lazy.cs @@ -1,6 +1,6 @@ using System; -namespace LibGit2Sharp.Core +namespace LibGit2Sharp.Core.Compat { /// <summary> /// Provides support for lazy initialization. diff --git a/LibGit2Sharp/Core/Compat/Tuple.cs b/LibGit2Sharp/Core/Compat/Tuple.cs new file mode 100644 index 00000000..cc863032 --- /dev/null +++ b/LibGit2Sharp/Core/Compat/Tuple.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; + +namespace LibGit2Sharp.Core.Compat +{ + /// <summary> + /// Represents a 2-tuple, or pair. + /// </summary> + /// <typeparam name = "T1">The type of the tuple's first component.</typeparam> + /// <typeparam name = "T2">The type of the tuple's second component.</typeparam> + public class Tuple<T1, T2> + { + private readonly KeyValuePair<T1, T2> kvp; + + /// <summary> + /// Initializes a new instance of the <see cref="Tuple{T1,T2}"/> class. + /// </summary> + /// <param name="item1">The value of the tuple's first component.</param> + /// <param name="item2">The value of the tuple's second component.</param> + public Tuple(T1 item1, T2 item2) + { + kvp = new KeyValuePair<T1, T2>(item1, item2); + } + + /// <summary> + /// Gets the value of the current <see cref = "Tuple{T1,T2}" /> object's second component. + /// </summary> + public T2 Item2 + { + get { return kvp.Value; } + } + + /// <summary> + /// Gets the value of the current <see cref = "Tuple{T1,T2}" /> object's first component. + /// </summary> + public T1 Item1 + { + get { return kvp.Key; } + } + + /// <summary> + /// Returns the hash code for the current <see cref = "Tuple{T1,T2}" /> object. + /// </summary> + /// <returns>A 32-bit signed integer hash code.</returns> + public override int GetHashCode() + { + return kvp.GetHashCode(); + } + + /// <summary> + /// Returns a value that indicates whether the current <see cref = "Tuple{T1,T2}" /> object is equal to a specified object. + /// </summary> + /// <param name = "obj">The object to compare with this instance.</param> + /// <returns>true if the current instance is equal to the specified object; otherwise, false.</returns> + public override bool Equals(object obj) + { + if (!(obj is Tuple<T1, T2>)) + { + return false; + } + return kvp.Equals(((Tuple<T1, T2>)obj).kvp); + } + + + } +} diff --git a/LibGit2Sharp/DirectReference.cs b/LibGit2Sharp/DirectReference.cs index 17fb4bf8..a75fe6cc 100644 --- a/LibGit2Sharp/DirectReference.cs +++ b/LibGit2Sharp/DirectReference.cs @@ -1,4 +1,5 @@ using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; namespace LibGit2Sharp { diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 8b29323b..923fd88d 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -52,6 +52,7 @@ <Compile Include="CommitCollection.cs" /> <Compile Include="Configuration.cs" /> <Compile Include="ConfigurationLevel.cs" /> + <Compile Include="Core\Compat\Tuple.cs" /> <Compile Include="Core\EnumExtensions.cs" /> <Compile Include="DetachedHead.cs" /> <Compile Include="LibGit2Exception.cs" /> @@ -67,7 +68,7 @@ <Compile Include="FileStatus.cs" /> <Compile Include="Core\GitTime.cs" /> <Compile Include="Core\IntPtrExtensions.cs" /> - <Compile Include="Core\Lazy.cs" /> + <Compile Include="Core\Compat\Lazy.cs" /> <Compile Include="Core\NativeMethods.cs" /> <Compile Include="Core\SafeHandleExtensions.cs" /> <Compile Include="Core\ObjectSafeWrapper.cs" /> @@ -132,6 +133,6 @@ <ItemGroup> <NativeBinaries Include="$(MSBuildProjectDirectory)\..\Lib\NativeBinaries\**\*.*" /> </ItemGroup> - <Copy SourceFiles="@(NativeBinaries)" DestinationFiles="@(NativeBinaries->'$(OutputPath)NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" /> + <Copy SourceFiles="@(NativeBinaries)" DestinationFiles="@(NativeBinaries->'$(OutputPath)NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" /> </Target> </Project>
\ No newline at end of file diff --git a/LibGit2Sharp/NamedReference.cs b/LibGit2Sharp/NamedReference.cs index 8eb9035a..334bd880 100644 --- a/LibGit2Sharp/NamedReference.cs +++ b/LibGit2Sharp/NamedReference.cs @@ -1,5 +1,6 @@ using System; using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; namespace LibGit2Sharp { diff --git a/LibGit2Sharp/Reference.cs b/LibGit2Sharp/Reference.cs index 41276aff..eef973fd 100644 --- a/LibGit2Sharp/Reference.cs +++ b/LibGit2Sharp/Reference.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Runtime.InteropServices; using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; namespace LibGit2Sharp { diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 335d21b4..99159a26 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -1,6 +1,7 @@ using System; using System.IO; using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; namespace LibGit2Sharp { diff --git a/LibGit2Sharp/TagAnnotation.cs b/LibGit2Sharp/TagAnnotation.cs index ac3cc37d..0c519fb2 100644 --- a/LibGit2Sharp/TagAnnotation.cs +++ b/LibGit2Sharp/TagAnnotation.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; namespace LibGit2Sharp { diff --git a/LibGit2Sharp/TreeEntry.cs b/LibGit2Sharp/TreeEntry.cs index bde6b2e5..3fc488c0 100755 --- a/LibGit2Sharp/TreeEntry.cs +++ b/LibGit2Sharp/TreeEntry.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using LibGit2Sharp.Core; +using LibGit2Sharp.Core.Compat; namespace LibGit2Sharp { |