mirror of
https://github.com/actions/runner.git
synced 2025-12-18 16:26:58 +00:00
GitHub Actions Runner
This commit is contained in:
45
src/Sdk/DTWebApi/WebApi/DemandJsonConverter.cs
Normal file
45
src/Sdk/DTWebApi/WebApi/DemandJsonConverter.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using GitHub.Services.WebApi;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace GitHub.DistributedTask.WebApi
|
||||
{
|
||||
internal sealed class DemandJsonConverter : VssSecureJsonConverter
|
||||
{
|
||||
public override Boolean CanConvert(Type objectType)
|
||||
{
|
||||
return typeof(Demand).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo());
|
||||
}
|
||||
|
||||
public override Object ReadJson(
|
||||
JsonReader reader,
|
||||
Type objectType,
|
||||
Object existingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
if (existingValue == null && reader.TokenType == JsonToken.String)
|
||||
{
|
||||
Demand demand;
|
||||
if (Demand.TryParse((String)reader.Value, out demand))
|
||||
{
|
||||
existingValue = demand;
|
||||
}
|
||||
}
|
||||
|
||||
return existingValue;
|
||||
}
|
||||
|
||||
public override void WriteJson(
|
||||
JsonWriter writer,
|
||||
Object value,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
base.WriteJson(writer, value, serializer);
|
||||
if (value != null)
|
||||
{
|
||||
writer.WriteValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user