mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-07 12:37:45 +00:00
ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.598.0
This commit is contained in:
62
LukeHagar/PlexAPI/SDK/Utils/OpenEnumConverter.cs
Normal file
62
LukeHagar/PlexAPI/SDK/Utils/OpenEnumConverter.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost when
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
#nullable enable
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
namespace LukeHagar.PlexAPI.SDK.Utils
|
||||
{
|
||||
internal class OpenEnumConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(System.Type objectType)
|
||||
{
|
||||
return objectType.GetMethod("Of") != null && objectType.GetMethod("ToString") != null;
|
||||
}
|
||||
|
||||
public override object? ReadJson(
|
||||
JsonReader reader,
|
||||
System.Type objectType,
|
||||
object? existingValue,
|
||||
JsonSerializer serializer
|
||||
)
|
||||
{
|
||||
if (reader.Value == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var method = objectType.GetMethod("Of");
|
||||
if (method == null)
|
||||
{
|
||||
throw new Exception($"Unable to find Of method on {objectType}");
|
||||
}
|
||||
try {
|
||||
return method.Invoke(null, new[] { reader.Value });
|
||||
} catch(System.Reflection.TargetInvocationException e) {
|
||||
throw new Newtonsoft.Json.JsonSerializationException("Unable to convert value to open enum", e);
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object? obj, JsonSerializer serializer)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
writer.WriteValue("null");
|
||||
return;
|
||||
}
|
||||
|
||||
var valueProp = obj.GetType().GetProperty("Value");
|
||||
if (valueProp == null)
|
||||
{
|
||||
throw new Exception($"{obj.GetType()} does not have a Value property");
|
||||
}
|
||||
|
||||
writer.WriteValue(valueProp.GetValue(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user