Created
May 8, 2025 17:53
-
-
Save Alxandr/f4b7547387a933eb5f84297acc6693d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public enum VariantType | |
{ | |
LeftChild, | |
RightChild1, | |
RightChild2, | |
RightGrandChild, | |
} | |
[PolymorphicFieldValueRecord] | |
[PolymorphicDerivedType(typeof(LeftChild), VariantType.LeftChild)] | |
[PolymorphicDerivedType(typeof(RightChild), VariantType.RightChild1)] | |
[PolymorphicDerivedType(typeof(RightChild), VariantType.RightChild2)] | |
[PolymorphicDerivedType(typeof(RightGrandChild), VariantType.RightGrandChild)] | |
public record Base | |
{ | |
public Base(VariantType variant) | |
{ | |
Type = variant; | |
} | |
public NonExhaustiveEnum<VariantType> Type { get; } | |
public required string RequiredBaseProperty { get; init; } | |
public required FieldValue<string> OptionalBaseProperty { get; init; } | |
} | |
[PolymorphicFieldValueRecord] | |
public record LeftChild() | |
: Base(VariantType.LeftChild) | |
{ | |
public required string RequiredLeftChildProperty { get; init; } | |
public required FieldValue<string> OptionalLeftChildProperty { get; init; } | |
} | |
[PolymorphicFieldValueRecord] | |
public record RightChild | |
: Base | |
{ | |
public RightChild(VariantType variant) | |
: base(variant) | |
{ | |
} | |
public required string RequiredRightChildProperty { get; init; } | |
public required FieldValue<string> OptionalRightChildProperty { get; init; } | |
} | |
[PolymorphicFieldValueRecord] | |
public record RightGrandChild(VariantType variant) | |
: RightChild(variant) | |
{ | |
public required string RequiredRightGrandChildProperty { get; init; } | |
public required FieldValue<string> OptionalRightGrandChildProperty { get; init; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment