Skip to content

Commit

Permalink
Build fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
peters committed Jul 30, 2024
1 parent 842a203 commit 6a9357a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@
</PackageVersion>
<PackageVersion Include="XunitXml.TestLogger" Version="4.0.254" />
<PackageVersion Include="YamlDotNet" Version="16.0.0" />
<!-- Transitive dependencies -->
<PackageVersion Include="System.Formats.Asn1" Version="[8.0.1,)" />
</ItemGroup>
</Project>
20 changes: 11 additions & 9 deletions src/Snap/Core/Yaml/TypeConverters/OsPlatformYamlTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
Expand All @@ -8,24 +8,26 @@ namespace Snap.Core.Yaml.TypeConverters;

internal sealed class OsPlatformYamlTypeConverter : IYamlTypeConverter
{
public bool Accepts(Type type)
{
return type == typeof(OSPlatform);
}
public bool Accepts(Type type) => type == typeof(OSPlatform);

public object ReadYaml(IParser parser, Type type)
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var osPlatform = ((Scalar)parser.Current)?.Value;
parser.MoveNext();
return TryCreateOsPlatform(osPlatform);
}

public void WriteYaml(IEmitter emitter, object value, Type type)
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
var osPlatformStr = ((OSPlatform)value).ToString().ToLowerInvariant();
if (value is not OSPlatform osPlatform)
{
throw new ArgumentException("Value is not an OSPlatform", nameof(value));
}

var osPlatformStr = osPlatform.ToString().ToLowerInvariant();
emitter.Emit(new Scalar(osPlatformStr));
}

static OSPlatform TryCreateOsPlatform(string osPlatform)
{
if (string.IsNullOrWhiteSpace(osPlatform))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using NuGet.Versioning;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
Expand All @@ -13,15 +13,15 @@ public bool Accepts(Type type)
return type == typeof(SemanticVersion);
}

public object ReadYaml(IParser parser, Type type)
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var semanticVersionStr = ((Scalar)parser.Current)?.Value;
parser.MoveNext();
SemanticVersion.TryParse(semanticVersionStr, out var semanticVersion);
return semanticVersion;
}

public void WriteYaml(IEmitter emitter, object value, Type type)
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
var semanticVersionStr = ((SemanticVersion)value)?.ToNormalizedString() ?? string.Empty;
emitter.Emit(new Scalar(semanticVersionStr));
Expand Down
6 changes: 3 additions & 3 deletions src/Snap/Core/Yaml/TypeConverters/UriYamlTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
Expand All @@ -12,15 +12,15 @@ public bool Accepts(Type type)
return type == typeof(Uri);
}

public object ReadYaml(IParser parser, Type type)
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var uriStr = ((Scalar)parser.Current)?.Value;
parser.MoveNext();
Uri.TryCreate(uriStr, UriKind.Absolute, out var uri);
return uri;
}

public void WriteYaml(IEmitter emitter, object value, Type type)
public void WriteYaml(IEmitter emitter, object value, Type type, ObjectSerializer serializer)
{
var uriStr = ((Uri)value)?.ToString() ?? string.Empty;
emitter.Emit(new Scalar(uriStr));
Expand Down

0 comments on commit 6a9357a

Please sign in to comment.