Skip to content

Commit

Permalink
Merge branch 'peters-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Hauser committed May 13, 2014
2 parents 4ffd866 + 70f04d5 commit 02c3ce4
Show file tree
Hide file tree
Showing 8 changed files with 1,790 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.buildtools/
bin/
obj/
TestResults/
Expand Down
19 changes: 19 additions & 0 deletions Semver.Test/SemVersionTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Semver.Test
Expand Down Expand Up @@ -693,5 +696,21 @@ public void TestChangeBuild()
Assert.AreEqual("alpha", v2.Prerelease);
Assert.AreEqual("rel", v2.Build);
}

[TestMethod]
public void TestSerialization()
{
var semVer = new SemVersion(1, 2, 3, "alpha", "dev");
SemVersion semVerSerializedDeserialized;
using (var ms = new MemoryStream())
{
var bf = new BinaryFormatter();
bf.Serialize(ms, semVer);
ms.Position = 0;
semVerSerializedDeserialized = (SemVersion) bf.Deserialize(ms);
}
Assert.AreEqual(semVer, semVerSerializedDeserialized);
}

}
}
5 changes: 3 additions & 2 deletions Semver/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
[assembly: AssemblyCopyright("Copyright © 2013 Max Hauser")]
[assembly: ComVisible(false)]
[assembly: Guid("e208ca67-5b59-45d9-a29a-7f30137d3beb")]
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyVersion("1.1.2")]
[assembly: AssemblyFileVersion("1.1.2")]
[assembly: AssemblyInformationalVersion("1.1.2")]
31 changes: 29 additions & 2 deletions Semver/SemVersion.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Globalization;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text.RegularExpressions;

namespace Semver
Expand All @@ -8,7 +10,8 @@ namespace Semver
/// A semantic version implementation.
/// Conforms to v2.0.0 of http://semver.org/
/// </summary>
public sealed class SemVersion : IComparable<SemVersion>, IComparable
[Serializable]
public sealed class SemVersion : IComparable<SemVersion>, IComparable, ISerializable
{
static Regex parseEx =
new Regex(@"^(?<major>\d+)" +
Expand All @@ -18,6 +21,23 @@ public sealed class SemVersion : IComparable<SemVersion>, IComparable
@"(\+(?<build>[0-9A-Za-z\-\.]+))?$",
RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.ExplicitCapture);

/// <summary>
/// Initializes a new instance of the <see cref="SemVersion" /> class.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
/// <exception cref="ArgumentNullException"></exception>
private SemVersion(SerializationInfo info, StreamingContext context)
{
if (info == null) throw new ArgumentNullException("info");
var semVersion = Parse(info.GetString("SemVersion"));
Major = semVersion.Major;
Minor = semVersion.Minor;
Patch = semVersion.Patch;
Prerelease = semVersion.Prerelease;
Build = semVersion.Build;
}

/// <summary>
/// Initializes a new instance of the <see cref="SemVersion" /> class.
/// </summary>
Expand Down Expand Up @@ -117,7 +137,7 @@ public static bool TryParse(string version, out SemVersion semver, bool strict =
semver = Parse(version, strict);
return true;
}
catch(Exception)
catch (Exception)
{
semver = null;
return false;
Expand Down Expand Up @@ -391,6 +411,13 @@ public override int GetHashCode()
}
}

[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null) throw new ArgumentNullException("info");
info.AddValue("SemVersion", ToString());
}

/// <summary>
/// Implicit conversion from string to SemVersion.
/// </summary>
Expand Down
12 changes: 3 additions & 9 deletions Semver/Semver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Semver.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SemVersion.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
7 changes: 7 additions & 0 deletions Semver/Semver.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@
<copyright>Copyright 2013</copyright>
<tags>semver semantic version</tags>
</metadata>
<files>
<file src="$outputfolder$\v2.0\semver.dll" target="lib\net20" />
<file src="$outputfolder$\v3.5\semver.dll" target="lib\net35" />
<file src="$outputfolder$\v4.0\semver.dll" target="lib\net40" />
<file src="$outputfolder$\v4.5\semver.dll" target="lib\net45" />
<file src="$outputfolder$\v4.5.1\semver.dll" target="lib\net451" />
</files>
</package>
Loading

0 comments on commit 02c3ce4

Please sign in to comment.