Skip to content
Closed
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
  •  
  •  
  •  
111 changes: 80 additions & 31 deletions src/libs/Together/Generated/Together.AllOf.2.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Together
/// <summary>
///
/// </summary>
public readonly partial struct AllOf<[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] T1, [global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] T2> : global::System.IEquatable<AllOf<T1, T2>>
public readonly partial struct AllOf<T1, T2> : global::System.IEquatable<AllOf<T1, T2>>
{
/// <summary>
///
Expand All @@ -25,6 +25,26 @@ namespace Together
#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() => IsValue1
? Value1!
: throw new global::System.InvalidOperationException($"Expected union variant 'Value1' but the value was {ToString()}.");

/// <summary>
///
/// </summary>
Expand All @@ -41,6 +61,26 @@ namespace Together
[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() => IsValue2
? Value2!
: throw new global::System.InvalidOperationException($"Expected union variant 'Value2' but the value was {ToString()}.");
/// <summary>
///
/// </summary>
Expand All @@ -59,6 +99,11 @@ public AllOf(T1? value)
Value1 = value;
}

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

/// <summary>
///
/// </summary>
Expand All @@ -77,6 +122,11 @@ public AllOf(T2? value)
Value2 = value;
}

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

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -105,42 +155,17 @@ Value1 as object
Value2?.ToString()
;

private static bool RequiresValue<[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] TValue>() => RequirementCache<TValue>.Value;

private static bool DetermineRequiresValue([global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] global::System.Type type)
private static bool RequiresValue<TValue>()
{
var type = typeof(TValue);
if (global::System.Nullable.GetUnderlyingType(type) != null)
{
return false;
}

if (type.IsValueType ||
type == typeof(string) ||
type.IsArray)
{
return true;
}

foreach (var property in type.GetProperties(global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Public))
{
foreach (var attributeData in property.CustomAttributes)
{
var attributeTypeName = attributeData.AttributeType.FullName;
if (attributeTypeName == "System.Text.Json.Serialization.JsonRequiredAttribute" ||
attributeTypeName == "Newtonsoft.Json.JsonRequiredAttribute" ||
attributeTypeName == "System.Runtime.CompilerServices.RequiredMemberAttribute")
{
return true;
}
}
}

return false;
}

private static class RequirementCache<[global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] TValue>
{
public static readonly bool Value = DetermineRequiresValue(typeof(TValue));
return type.IsValueType ||
type == typeof(string) ||
type.IsArray;
}


Expand Down Expand Up @@ -182,6 +207,30 @@ public bool Validate()
/// </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 void Switch(
global::System.Action<T1>? value1 = null,
global::System.Action<T2>? value2 = null,
bool validate = true)
{
Expand Down
74 changes: 74 additions & 0 deletions src/libs/Together/Generated/Together.AnyOf.2.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ namespace Together
#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() => IsValue1
? Value1!
: throw new global::System.InvalidOperationException($"Expected union variant 'Value1' but the value was {ToString()}.");

/// <summary>
///
/// </summary>
Expand All @@ -41,6 +61,26 @@ namespace Together
[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() => IsValue2
? Value2!
: throw new global::System.InvalidOperationException($"Expected union variant 'Value2' but the value was {ToString()}.");
/// <summary>
///
/// </summary>
Expand All @@ -59,6 +99,11 @@ public AnyOf(T1? value)
Value1 = value;
}

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

/// <summary>
///
/// </summary>
Expand All @@ -77,6 +122,11 @@ public AnyOf(T2? value)
Value2 = value;
}

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

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -143,6 +193,30 @@ public bool Validate()
/// </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 void Switch(
global::System.Action<T1>? value1 = null,
global::System.Action<T2>? value2 = null,
bool validate = true)
{
Expand Down
Loading