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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

/// <summary>
Expand All @@ -51,26 +51,26 @@ 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::tryAGI.OpenAI.ResponseFormat? FromJson(
public static global::tryAGI.OpenAI.AllOf<T1, T2>? FromJson(
string json,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Deserialize<global::tryAGI.OpenAI.ResponseFormat>(
return global::System.Text.Json.JsonSerializer.Deserialize<global::tryAGI.OpenAI.AllOf<T1, T2>>(
json,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerContext.
/// </summary>
public static async global::System.Threading.Tasks.ValueTask<global::tryAGI.OpenAI.ResponseFormat?> FromJsonStreamAsync(
public static async global::System.Threading.Tasks.ValueTask<global::tryAGI.OpenAI.AllOf<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::tryAGI.OpenAI.ResponseFormat),
jsonSerializerContext).ConfigureAwait(false)) as global::tryAGI.OpenAI.ResponseFormat?;
typeof(global::tryAGI.OpenAI.AllOf<T1, T2>),
jsonSerializerContext).ConfigureAwait(false)) as global::tryAGI.OpenAI.AllOf<T1, T2>?;
}

/// <summary>
Expand All @@ -80,11 +80,11 @@ 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::tryAGI.OpenAI.ResponseFormat?> FromJsonStreamAsync(
public static global::System.Threading.Tasks.ValueTask<global::tryAGI.OpenAI.AllOf<T1, T2>?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::tryAGI.OpenAI.ResponseFormat?>(
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::tryAGI.OpenAI.AllOf<T1, T2>?>(
jsonStream,
jsonSerializerOptions);
}
Expand Down
213 changes: 213 additions & 0 deletions src/libs/tryAGI.OpenAI/Generated/AllOf.2.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@

#nullable enable

namespace tryAGI.OpenAI
{
/// <summary>
///
/// </summary>
public readonly partial struct AllOf<T1, T2> : global::System.IEquatable<AllOf<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 static implicit operator AllOf<T1, T2>(T1 value) => new AllOf<T1, T2>(value);

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

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

/// <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 static implicit operator AllOf<T1, T2>(T2 value) => new AllOf<T1, T2>(value);

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

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

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

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

/// <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 (IsValue1 && value1 != null)
{
return value1(Value1!);
}
else if (IsValue2 && value2 != null)
{
return value2(Value2!);
}

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 (IsValue1)
{
value1?.Invoke(Value1!);
}
else if (IsValue2)
{
value2?.Invoke(Value2!);
}
}

/// <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(AllOf<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 ==(AllOf<T1, T2> obj1, AllOf<T1, T2> obj2)
{
return global::System.Collections.Generic.EqualityComparer<AllOf<T1, T2>>.Default.Equals(obj1, obj2);
}

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

/// <summary>
///
/// </summary>
public override bool Equals(object? obj)
{
return obj is AllOf<T1, T2> o && Equals(o);
}
}
}
86 changes: 86 additions & 0 deletions src/libs/tryAGI.OpenAI/Generated/JsonConverters.AllOf2.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#nullable enable

namespace tryAGI.OpenAI.JsonConverters
{
/// <inheritdoc />
public class AllOfJsonConverter<T1, T2> : global::System.Text.Json.Serialization.JsonConverter<global::tryAGI.OpenAI.AllOf<T1, T2>>
{
/// <inheritdoc />
public override global::tryAGI.OpenAI.AllOf<T1, T2> Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
options = options ?? throw new global::System.ArgumentNullException(nameof(options));
var typeInfoResolver = options.TypeInfoResolver ?? throw new global::System.InvalidOperationException("TypeInfoResolver is not set.");

var
readerCopy = reader;
T1? value1 = default;
try
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(T1), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<T1> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(T1).Name}");
value1 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, typeInfo);
}
catch (global::System.Text.Json.JsonException)
{
}

readerCopy = reader;
T2? value2 = default;
try
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(T2), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<T2> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(T2).Name}");
value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, typeInfo);
}
catch (global::System.Text.Json.JsonException)
{
}

var result = new global::tryAGI.OpenAI.AllOf<T1, T2>(
value1,
value2
);

if (value1 != null)
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(T1), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<T1> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(T1).Name}");
_ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
}
else if (value2 != null)
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(T2), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<T2> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(T2).Name}");
_ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo);
}

return result;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::tryAGI.OpenAI.AllOf<T1, T2> value,
global::System.Text.Json.JsonSerializerOptions options)
{
options = options ?? throw new global::System.ArgumentNullException(nameof(options));
var typeInfoResolver = options.TypeInfoResolver ?? throw new global::System.InvalidOperationException("TypeInfoResolver is not set.");

if (value.IsValue1)
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(T1), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<T1?> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(T1).Name}");
global::System.Text.Json.JsonSerializer.Serialize(writer, value.Value1, typeInfo);
}
else if (value.IsValue2)
{
var typeInfo = typeInfoResolver.GetTypeInfo(typeof(T2), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<T2?> ??
throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(T2).Name}");
global::System.Text.Json.JsonSerializer.Serialize(writer, value.Value2, typeInfo);
}
}
}
}
Loading
Loading