Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ModerationAPI
{
public sealed partial class ModerationAudioRequest
public readonly partial struct AnyOf<T1, T2>
{
/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerContext.
Expand Down Expand Up @@ -47,20 +47,20 @@ public string ToJson(
/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerContext.
/// </summary>
public static global::ModerationAPI.ModerationAudioRequest? FromJson(
public static global::ModerationAPI.AnyOf<T1, T2>? FromJson(
string json,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Deserialize(
json,
typeof(global::ModerationAPI.ModerationAudioRequest),
jsonSerializerContext) as global::ModerationAPI.ModerationAudioRequest;
typeof(global::ModerationAPI.AnyOf<T1, T2>),
jsonSerializerContext) as global::ModerationAPI.AnyOf<T1, T2>?;
}

/// <summary>
/// Deserializes a JSON string using the generated default JsonSerializerContext.
/// </summary>
public static global::ModerationAPI.ModerationAudioRequest? FromJson(
public static global::ModerationAPI.AnyOf<T1, T2>? FromJson(
string json)
{
return FromJson(
Expand All @@ -75,7 +75,7 @@ public string ToJson(
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::ModerationAPI.ModerationAudioRequest? FromJson(
public static global::ModerationAPI.AnyOf<T1, T2>? FromJson(
string json,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
Expand All @@ -86,28 +86,28 @@ public string ToJson(
global::ModerationAPI.SourceGenerationContext.Default);
}

return global::System.Text.Json.JsonSerializer.Deserialize<global::ModerationAPI.ModerationAudioRequest>(
return global::System.Text.Json.JsonSerializer.Deserialize<global::ModerationAPI.AnyOf<T1, T2>>(
json,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerContext.
/// </summary>
public static async global::System.Threading.Tasks.ValueTask<global::ModerationAPI.ModerationAudioRequest?> FromJsonStreamAsync(
public static async global::System.Threading.Tasks.ValueTask<global::ModerationAPI.AnyOf<T1, T2>?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return (await global::System.Text.Json.JsonSerializer.DeserializeAsync(
jsonStream,
typeof(global::ModerationAPI.ModerationAudioRequest),
jsonSerializerContext).ConfigureAwait(false)) as global::ModerationAPI.ModerationAudioRequest;
typeof(global::ModerationAPI.AnyOf<T1, T2>),
jsonSerializerContext).ConfigureAwait(false)) as global::ModerationAPI.AnyOf<T1, T2>?;
}

/// <summary>
/// Deserializes a JSON stream using the generated default JsonSerializerContext.
/// </summary>
public static global::System.Threading.Tasks.ValueTask<global::ModerationAPI.ModerationAudioRequest?> FromJsonStreamAsync(
public static global::System.Threading.Tasks.ValueTask<global::ModerationAPI.AnyOf<T1, T2>?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream)
{
return FromJsonStreamAsync(
Expand All @@ -122,7 +122,7 @@ public string ToJson(
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::System.Threading.Tasks.ValueTask<global::ModerationAPI.ModerationAudioRequest?> FromJsonStreamAsync(
public static global::System.Threading.Tasks.ValueTask<global::ModerationAPI.AnyOf<T1, T2>?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
Expand All @@ -133,7 +133,7 @@ public string ToJson(
global::ModerationAPI.SourceGenerationContext.Default);
}

return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::ModerationAPI.ModerationAudioRequest?>(
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::ModerationAPI.AnyOf<T1, T2>?>(
jsonStream,
jsonSerializerOptions);
}
Expand Down
294 changes: 294 additions & 0 deletions src/libs/ModerationAPI/Generated/ModerationAPI.AnyOf.2.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@

#nullable enable

namespace ModerationAPI
{
/// <summary>
///
/// </summary>
public readonly partial struct AnyOf<T1, T2> : global::System.IEquatable<AnyOf<T1, T2>>
{
/// <summary>
///
/// </summary>
#if NET6_0_OR_GREATER
public T1? Value1 { get; init; }
#else
public T1? Value1 { get; }
#endif

/// <summary>
///
/// </summary>
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Value1))]
#endif
public bool IsValue1 => Value1 != null;

/// <summary>
///
/// </summary>
public bool TryPickValue1(
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
out T1? value)
{
value = Value1;
return IsValue1;
}

/// <summary>
///
/// </summary>
public T1 PickValue1() => Value1 is { } value
? value
: throw new global::System.InvalidOperationException($"Expected union variant 'Value1' but the value was {ToString()}.");

/// <summary>
///
/// </summary>
#if NET6_0_OR_GREATER
public T2? Value2 { get; init; }
#else
public T2? Value2 { get; }
#endif

/// <summary>
///
/// </summary>
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Value2))]
#endif
public bool IsValue2 => Value2 != null;

/// <summary>
///
/// </summary>
public bool TryPickValue2(
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
out T2? value)
{
value = Value2;
return IsValue2;
}

/// <summary>
///
/// </summary>
public T2 PickValue2() => Value2 is { } value
? value
: throw new global::System.InvalidOperationException($"Expected union variant 'Value2' but the value was {ToString()}.");
/// <summary>
///
/// </summary>
public static implicit operator AnyOf<T1, T2>(T1 value) => new AnyOf<T1, T2>((T1?)value);

/// <summary>
///
/// </summary>
public static implicit operator T1?(AnyOf<T1, T2> @this) => @this.Value1;

/// <summary>
///
/// </summary>
public AnyOf(T1? value)
{
Value1 = value;
}

/// <summary>
///
/// </summary>
public static AnyOf<T1, T2> FromValue1(T1? value) => new AnyOf<T1, T2>(value);

/// <summary>
///
/// </summary>
public static implicit operator AnyOf<T1, T2>(T2 value) => new AnyOf<T1, T2>((T2?)value);

/// <summary>
///
/// </summary>
public static implicit operator T2?(AnyOf<T1, T2> @this) => @this.Value2;

/// <summary>
///
/// </summary>
public AnyOf(T2? value)
{
Value2 = value;
}

/// <summary>
///
/// </summary>
public static AnyOf<T1, T2> FromValue2(T2? value) => new AnyOf<T1, T2>(value);

/// <summary>
///
/// </summary>
public AnyOf(
T1? value1,
T2? value2
)
{
Value1 = value1;
Value2 = value2;
}

/// <summary>
///
/// </summary>
public object? Object =>
Value2 as object ??
Value1 as object
;

/// <summary>
///
/// </summary>
public override string? ToString() =>
Value1?.ToString() ??
Value2?.ToString()
;

/// <summary>
///
/// </summary>
public bool Validate()
{
return IsValue1 || IsValue2;
}

/// <summary>
///
/// </summary>
public TResult? Match<TResult>(
global::System.Func<T1, TResult>? value1 = null,
global::System.Func<T2, TResult>? value2 = null,
bool validate = true)
{
if (validate)
{
Validate();
}

if (Value1 is { } __value0 && value1 != null)
{
return value1(__value0);
}
else if (Value2 is { } __value1 && value2 != null)
{
return value2(__value1);
}

return default(TResult);
}

/// <summary>
///
/// </summary>
public void Match(
global::System.Action<T1>? value1 = null,

global::System.Action<T2>? value2 = null,
bool validate = true)
{
if (validate)
{
Validate();
}

if (Value1 is { } __value0)
{
value1?.Invoke(__value0);
}
else if (Value2 is { } __value1)
{
value2?.Invoke(__value1);
}
}

/// <summary>
///
/// </summary>
public void Switch(
global::System.Action<T1>? value1 = null,
global::System.Action<T2>? value2 = null,
bool validate = true)
{
if (validate)
{
Validate();
}

if (Value1 is { } __value0)
{
value1?.Invoke(__value0);
}
else if (Value2 is { } __value1)
{
value2?.Invoke(__value1);
}
}

/// <summary>
///
/// </summary>
public override int GetHashCode()
{
var fields = new object?[]
{
Value1,
typeof(T1),
Value2,
typeof(T2),
};
const int offset = unchecked((int)2166136261);
const int prime = 16777619;
static int HashCodeAggregator(int hashCode, object? value) => value == null
? (hashCode ^ 0) * prime
: (hashCode ^ value.GetHashCode()) * prime;

return global::System.Linq.Enumerable.Aggregate(fields, offset, HashCodeAggregator);
}

/// <summary>
///
/// </summary>
public bool Equals(AnyOf<T1, T2> other)
{
return
global::System.Collections.Generic.EqualityComparer<T1?>.Default.Equals(Value1, other.Value1) &&
global::System.Collections.Generic.EqualityComparer<T2?>.Default.Equals(Value2, other.Value2)
;
}

/// <summary>
///
/// </summary>
public static bool operator ==(AnyOf<T1, T2> obj1, AnyOf<T1, T2> obj2)
{
return global::System.Collections.Generic.EqualityComparer<AnyOf<T1, T2>>.Default.Equals(obj1, obj2);
}

/// <summary>
///
/// </summary>
public static bool operator !=(AnyOf<T1, T2> obj1, AnyOf<T1, T2> obj2)
{
return !(obj1 == obj2);
}

/// <summary>
///
/// </summary>
public override bool Equals(object? obj)
{
return obj is AnyOf<T1, T2> o && Equals(o);
}
}
}
Loading
Loading