File tree Expand file tree Collapse file tree 5 files changed +82
-6
lines changed Expand file tree Collapse file tree 5 files changed +82
-6
lines changed Original file line number Diff line number Diff line change 1313
1414 strategy :
1515 matrix :
16- dotnet : [ '3.1.x', '6.0.x' ]
16+ dotnet : [ '3.1.x' ]
1717 name : .NET ${{ matrix.dotnet }}
1818
1919 steps :
2525 - name : Restore dependencies
2626 run : dotnet restore
2727 - name : Build
28- run : dotnet build ./UUIDUtil --no-restore
28+ run : dotnet build --configuration Release --no-restore
2929 - name : Test
30- run : dotnet test ./UUIDUtil --no-build --verbosity normal
30+ run : dotnet test --no-restore --verbosity normal
Original file line number Diff line number Diff line change @@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
99## [ Unreleased]
1010
11+ ## [ v1.1.0] - 2022-05-31
12+ [ v1.1.0] ( https://github.com/TensionDev/UUIDUtil/releases/tag/v1.1.0 )
13+
14+ ### Added
15+ - Added support to convert System.Guid to TensionDev.UUID.Uuid and vice-versa.
16+
17+
1118## [ v1.0.0] - 2022-03-26
1219[ v1.0.0] ( https://github.com/TensionDev/UUIDUtil/releases/tag/v1.0.0 )
1320
Original file line number Diff line number Diff line change 77 <GeneratePackageOnBuild >true</GeneratePackageOnBuild >
88 <PackageRequireLicenseAcceptance >true</PackageRequireLicenseAcceptance >
99 <PackageId >TensionDev.UUID</PackageId >
10- <Version >1.0 .0</Version >
10+ <Version >1.1 .0</Version >
1111 <Authors >TensionDev amsga</Authors >
1212 <Company >TensionDev</Company >
1313 <Product >TensionDev.UUID</Product >
2020 <PackageTags >UUID GUID</PackageTags >
2121 <PackageReleaseNotes >Release with UUID / GUID Version 1, Version 3, Version 4 and Version 5.</PackageReleaseNotes >
2222 <NeutralLanguage >en-SG</NeutralLanguage >
23- <AssemblyVersion >1.0 .0.0</AssemblyVersion >
24- <FileVersion >1.0 .0.0</FileVersion >
23+ <AssemblyVersion >1.1 .0.0</AssemblyVersion >
24+ <FileVersion >1.1 .0.0</FileVersion >
2525 <IncludeSymbols >true</IncludeSymbols >
2626 <SymbolPackageFormat >snupkg</SymbolPackageFormat >
2727 </PropertyGroup >
Original file line number Diff line number Diff line change @@ -317,6 +317,45 @@ public byte[] ToByteArray()
317317 return vs ;
318318 }
319319
320+ /// <summary>
321+ /// Returns the System.Guid equivalent of this instance.
322+ /// </summary>
323+ /// <returns>A System.Guid object.</returns>
324+ public Guid ToGuid ( )
325+ {
326+ return new Guid ( ToString ( ) ) ;
327+ }
328+
329+ /// <summary>
330+ /// Return the Variant 2 version in System.Guid.
331+ /// </summary>
332+ /// <returns>A System.Guid object.</returns>
333+ public Guid ToVariant2 ( )
334+ {
335+ byte newClockSeq = ( byte ) ( _clock_seq_hi_and_reserved & 0x1F ) ;
336+ newClockSeq = ( byte ) ( newClockSeq | 0xC0 ) ;
337+ Uuid variant2 = new Uuid ( this . ToByteArray ( ) ) ;
338+
339+ variant2 . _clock_seq_hi_and_reserved = newClockSeq ;
340+
341+ return variant2 . ToGuid ( ) ;
342+ }
343+
344+ /// <summary>
345+ /// Returns the Variant 1 version in TensionDev.UUID.Uuid.
346+ /// </summary>
347+ /// <param name="guid">The System.Guid object to convert.</param>
348+ /// <returns>A TensionDev.UUID.Uuid object.</returns>
349+ public static Uuid ToVariant1 ( Guid guid )
350+ {
351+ Uuid variant1 = new Uuid ( guid . ToString ( ) ) ;
352+ byte newClockSeq = ( byte ) ( variant1 . _clock_seq_hi_and_reserved & 0x3F ) ;
353+ newClockSeq = ( byte ) ( newClockSeq | 0x80 ) ;
354+ variant1 . _clock_seq_hi_and_reserved = newClockSeq ;
355+
356+ return variant1 ;
357+ }
358+
320359 /// <summary>
321360 /// Returns a string representation of the value of this instance as per RFC 4122 Section 3.
322361 /// </summary>
Original file line number Diff line number Diff line change @@ -199,6 +199,36 @@ public void TestToByteArray3()
199199 Assert . Equal ( expected , actual ) ;
200200 }
201201
202+ [ Fact ]
203+ public void TestToGuid ( )
204+ {
205+ Guid expected = new Guid ( "7d444840-9dc0-11d1-b245-5ffdce74fad2" ) ;
206+ TensionDev . UUID . Uuid uuid = new TensionDev . UUID . Uuid ( "7d444840-9dc0-11d1-b245-5ffdce74fad2" ) ;
207+
208+ Guid actual = uuid . ToGuid ( ) ;
209+ Assert . Equal ( expected , actual ) ;
210+ }
211+
212+ [ Fact ]
213+ public void TestToVariant2 ( )
214+ {
215+ Guid expected = new Guid ( "7d444840-9dc0-11d1-d245-5ffdce74fad2" ) ;
216+ TensionDev . UUID . Uuid uuid = new TensionDev . UUID . Uuid ( "7d444840-9dc0-11d1-b245-5ffdce74fad2" ) ;
217+
218+ Guid actual = uuid . ToVariant2 ( ) ;
219+ Assert . Equal ( expected , actual ) ;
220+ }
221+
222+ [ Fact ]
223+ public void TestToVariant1 ( )
224+ {
225+ TensionDev . UUID . Uuid expected = new TensionDev . UUID . Uuid ( "7d444840-9dc0-11d1-9245-5ffdce74fad2" ) ;
226+ Guid guid = new Guid ( "7d444840-9dc0-11d1-d245-5ffdce74fad2" ) ;
227+
228+ TensionDev . UUID . Uuid actual = TensionDev . UUID . Uuid . ToVariant1 ( guid ) ;
229+ Assert . Equal ( expected , actual ) ;
230+ }
231+
202232 [ Fact ]
203233 public void TestToString1 ( )
204234 {
You can’t perform that action at this time.
0 commit comments