mirror of
https://github.com/LukeHagar/plexcsharp.git
synced 2025-12-06 20:47:49 +00:00
ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.598.0
This commit is contained in:
@@ -12,47 +12,65 @@ namespace LukeHagar.PlexAPI.SDK.Models.Requests
|
||||
using LukeHagar.PlexAPI.SDK.Utils;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// Current friend request status
|
||||
/// </summary>
|
||||
public enum Status
|
||||
[JsonConverter(typeof(OpenEnumConverter))]
|
||||
public class Status : IEquatable<Status>
|
||||
{
|
||||
[JsonProperty("accepted")]
|
||||
Accepted,
|
||||
}
|
||||
public static readonly Status Accepted = new Status("accepted");
|
||||
|
||||
public static class StatusExtension
|
||||
{
|
||||
public static string Value(this Status value)
|
||||
{
|
||||
return ((JsonPropertyAttribute)value.GetType().GetMember(value.ToString())[0].GetCustomAttributes(typeof(JsonPropertyAttribute), false)[0]).PropertyName ?? value.ToString();
|
||||
}
|
||||
|
||||
public static Status ToEnum(this string value)
|
||||
{
|
||||
foreach(var field in typeof(Status).GetFields())
|
||||
private static readonly Dictionary <string, Status> _knownValues =
|
||||
new Dictionary <string, Status> ()
|
||||
{
|
||||
var attributes = field.GetCustomAttributes(typeof(JsonPropertyAttribute), false);
|
||||
if (attributes.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
["accepted"] = Accepted
|
||||
};
|
||||
|
||||
var attribute = attributes[0] as JsonPropertyAttribute;
|
||||
if (attribute != null && attribute.PropertyName == value)
|
||||
{
|
||||
var enumVal = field.GetValue(null);
|
||||
private static readonly ConcurrentDictionary<string, Status> _values =
|
||||
new ConcurrentDictionary<string, Status>(_knownValues);
|
||||
|
||||
if (enumVal is Status)
|
||||
{
|
||||
return (Status)enumVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception($"Unknown value {value} for enum Status");
|
||||
private Status(string value)
|
||||
{
|
||||
if (value == null) throw new ArgumentNullException(nameof(value));
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string Value { get; }
|
||||
|
||||
public static Status Of(string value)
|
||||
{
|
||||
return _values.GetOrAdd(value, _ => new Status(value));
|
||||
}
|
||||
|
||||
public static implicit operator Status(string value) => Of(value);
|
||||
public static implicit operator string(Status status) => status.Value;
|
||||
|
||||
public static Status[] Values()
|
||||
{
|
||||
return _values.Values.ToArray();
|
||||
}
|
||||
|
||||
public override string ToString() => Value.ToString();
|
||||
|
||||
public bool IsKnown()
|
||||
{
|
||||
return _knownValues.ContainsKey(Value);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj) => Equals(obj as Status);
|
||||
|
||||
public bool Equals(Status? other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other is null) return false;
|
||||
return string.Equals(Value, other.Value);
|
||||
}
|
||||
|
||||
public override int GetHashCode() => Value.GetHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user