-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
3,438 additions
and
1,569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
86
src/libs/tryAGI.OpenAI/Generated/JsonConverters.AllOf2.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.