Skip to content

Commit

Permalink
Merge pull request #13 from chickensoft-games/feat/nullable
Browse files Browse the repository at this point in the history
feat: add nullability information to type nodes
  • Loading branch information
jolexxa authored Oct 19, 2024
2 parents b964fdc + e4426ef commit 53e7efb
Show file tree
Hide file tree
Showing 30 changed files with 380 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public partial class TypeRegistry : Chickensoft.Introspection.ITypeRegistry {
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildOne)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("ConcreteChildOne", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildOne>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildOne>(), new Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildOne.MetatypeMetadata(), "concrete_child_one", 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("ConcreteChildTwo", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo>(), new Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo.MetatypeMetadata(), "concrete_child_two", 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("DerivedModel", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel>(), new Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel.MetatypeMetadata(), 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.GenericStruct<>)] = new Chickensoft.Introspection.TypeMetadata("GenericStruct<T>"),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("InitArgsModel", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel>(), new Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel.MetatypeMetadata(), "init_args_model", 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.JunkAttribute)] = new Chickensoft.Introspection.ConcreteTypeMetadata("JunkAttribute", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.JunkAttribute>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.JunkAttribute>()),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.MyContainerClass)] = new Chickensoft.Introspection.ConcreteTypeMetadata("MyContainerClass", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.MyContainerClass>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.MyContainerClass>()),
Expand All @@ -51,6 +52,7 @@ public partial class TypeRegistry : Chickensoft.Introspection.ITypeRegistry {
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.MyType<>)] = new Chickensoft.Introspection.TypeMetadata("MyType<T>"),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.NameOfId)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("NameOfId", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.NameOfId>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.NameOfId>(), new Chickensoft.Introspection.Generator.Tests.TestCases.NameOfId.MetatypeMetadata(), "NameOfId", 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.NoId)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("NoId", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.NoId>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.NoId>(), new Chickensoft.Introspection.Generator.Tests.TestCases.NoId.MetatypeMetadata(), 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.NullablePropertyTypes)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("NullablePropertyTypes", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.NullablePropertyTypes>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.NullablePropertyTypes>(), new Chickensoft.Introspection.Generator.Tests.TestCases.NullablePropertyTypes.MetatypeMetadata(), 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.One.Two)] = new Chickensoft.Introspection.ConcreteTypeMetadata("Two", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.One.Two>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.One.Two>()),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.One.Two.IThree.Four)] = new Chickensoft.Introspection.ConcreteTypeMetadata("Four", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.One.Two.IThree.Four>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.One.Two.IThree.Four>()),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.One.Two.IThree.Four.NestedType)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("NestedType", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.One.Two.IThree.Four.NestedType>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.One.Two.IThree.Four.NestedType>(), new Chickensoft.Introspection.Generator.Tests.TestCases.One.Two.IThree.Four.NestedType.MetatypeMetadata(), "nested_type", 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
IsRequired: false,
HasDefaultValue: true,
Getter: static (object obj) => ((MyModel)obj).Age,
Setter: static (object obj, object? value) => ((MyModel)obj).Age = (int)value,
Setter: static (object obj, object? value) => ((MyModel)obj).Age = (int?)value,
GenericType: new GenericType(
OpenType: typeof(int),
ClosedType: typeof(int),
IsNullable: true,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int?>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -51,6 +52,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand All @@ -58,6 +59,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(int),
ClosedType: typeof(int),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
Expand All @@ -71,20 +73,13 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
IsRequired: false,
HasDefaultValue: true,
Getter: static (object obj) => ((MyType)obj).OptionalFloat,
Setter: static (object obj, object? value) => ((MyType)obj).OptionalFloat = (Nullable<float>)value,
Setter: static (object obj, object? value) => ((MyType)obj).OptionalFloat = (float?)value,
GenericType: new GenericType(
OpenType: typeof(Nullable<>),
ClosedType: typeof(Nullable<float>),
Arguments: new GenericType[] {
new GenericType(
OpenType: typeof(float),
ClosedType: typeof(float),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<float>(),
GenericTypeGetter2: default
)
},
GenericTypeGetter: static receiver => receiver.Receive<Nullable<float>>(),
OpenType: typeof(float),
ClosedType: typeof(float),
IsNullable: true,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<float?>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -99,12 +94,13 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
IsRequired: false,
HasDefaultValue: true,
Getter: static (object obj) => ((MyType)obj).OptionalInt,
Setter: static (object obj, object? value) => ((MyType)obj).OptionalInt = (int)value,
Setter: static (object obj, object? value) => ((MyType)obj).OptionalInt = (int?)value,
GenericType: new GenericType(
OpenType: typeof(int),
ClosedType: typeof(int),
IsNullable: true,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int?>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
IsRequired: false,
HasDefaultValue: false,
Getter: static (object obj) => ((InitArgsModel)obj).Address,
Setter: static (object obj, object? value) => ((InitArgsModel)obj).Address = (string)value,
Setter: static (object obj, object? value) => ((InitArgsModel)obj).Address = (string?)value,
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: true,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string?>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -50,6 +51,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(int),
ClosedType: typeof(int),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
Expand All @@ -70,8 +72,9 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: true,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string?>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -90,6 +93,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(InitArgsEnum),
ClosedType: typeof(InitArgsEnum),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<InitArgsEnum>(),
GenericTypeGetter2: default
Expand All @@ -110,6 +114,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(InitArgsEnum),
ClosedType: typeof(InitArgsEnum),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<InitArgsEnum>(),
GenericTypeGetter2: default
Expand All @@ -130,6 +135,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down Expand Up @@ -166,7 +172,7 @@ public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, o
args = args ?? throw new System.ArgumentNullException(nameof(args), "Constructing InitArgsModel requires init args.");
return new InitArgsModel() {
Age = args.ContainsKey("Age") ? (int)args["Age"] : default(int)!,
Description = args.ContainsKey("Description") ? (string)args["Description"] : default(string)!,
Description = args.ContainsKey("Description") ? (string?)args["Description"] : default(string?),
HasAttended = args.ContainsKey("HasAttended") ? (InitArgsEnum)args["HasAttended"] : InitArgsEnum.No,
Name = args.ContainsKey("Name") ? (string)args["Name"] : default(string)!
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
GenericType: new GenericType(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: false,
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
Expand Down
Loading

0 comments on commit 53e7efb

Please sign in to comment.