Skip to content

feat: support value type metadata generation #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:warning

# Modifier preferences
dotnet_style_require_accessibility_modifiers = always:warning
dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:warning
dotnet_style_readonly_field = true:warning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace OtherNamespace.Altogether;
using Chickensoft.Introspection;

partial class A {
partial class ChildBaseFullyQualified : Chickensoft.Introspection.IIntrospective {
partial class ChildBaseFullyQualified : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AliasedStuff.Nested;
using X = OtherNamespace.Altogether.A;
using Y = OtherNamespace.Altogether.A.B;

partial class Child : Chickensoft.Introspection.IIntrospective {
partial class Child : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AliasedStuff.Nested;
using X = OtherNamespace.Altogether.A;
using Y = OtherNamespace.Altogether.A.B;

partial class Child2 : Chickensoft.Introspection.IIntrospective {
partial class Child2 : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace AliasedStuff.Nested;
using X = OtherNamespace.Altogether.A;
using Y = OtherNamespace.Altogether.A.B;

partial class DirectChild : Chickensoft.Introspection.IIntrospective {
partial class DirectChild : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OtherNamespace.Altogether;

partial class A {
partial class B {
partial class ChildBaseFullyQualified : Chickensoft.Introspection.IIntrospective {
partial class ChildBaseFullyQualified : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace BaseClasses.A;

using Chickensoft.Introspection;

partial class BaseClass : Chickensoft.Introspection.IIntrospective {
partial class BaseClass : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BaseClasses.B;
using BaseClasses.A;
using Chickensoft.Introspection;

partial class Child : Chickensoft.Introspection.IIntrospective {
partial class Child : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OtherNamespace.Altogether;
partial class A {
partial class B {
partial class C {
partial class ChildBaseFullyQualified : Chickensoft.Introspection.IIntrospective {
partial class ChildBaseFullyQualified : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace One.Two;

using Chickensoft.Introspection;

partial class A : Chickensoft.Introspection.IIntrospective {
partial class A : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace StaticUsings;
using Chickensoft.Introspection;
using static OtherNamespace.Altogether.A;

partial class ChildWithStaticBaseRef : Chickensoft.Introspection.IIntrospective {
partial class ChildWithStaticBaseRef : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#nullable enable
namespace Chickensoft.Introspection.Generator.Tests.TestCases;

partial record class SetOnlyProperty : Chickensoft.Introspection.IIntrospective {
partial record class SetOnlyProperty : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#pragma warning disable
#nullable enable
namespace Chickensoft.Introspection.Generator.Tests.TestCases;

partial record struct ValueTypeWithId : Chickensoft.Introspection.IIntrospective, Chickensoft.Introspection.IIdentifiable {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(ValueTypeWithId))).Metatype;

public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Type Type => typeof(ValueTypeWithId);
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public bool HasInitProperties { get; } = true;

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
new Chickensoft.Introspection.PropertyMetadata(
Name: "Description",
IsInit: true,
IsRequired: false,
HasDefaultValue: false,
Getter: static (object obj) => ((ValueTypeWithId)obj).Description,
Setter: null,
TypeNode: new Chickensoft.Introspection.TypeNode(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: true,
Arguments: System.Array.Empty<TypeNode>(),
GenericTypeGetter: static receiver => receiver.Receive<string?>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
}
),
new Chickensoft.Introspection.PropertyMetadata(
Name: "Number",
IsInit: true,
IsRequired: true,
HasDefaultValue: false,
Getter: static (object obj) => ((ValueTypeWithId)obj).Number,
Setter: null,
TypeNode: new Chickensoft.Introspection.TypeNode(
OpenType: typeof(int),
ClosedType: typeof(int),
IsNullable: false,
Arguments: System.Array.Empty<TypeNode>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
}
)
};

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(IdAttribute)] = new System.Attribute[] {
new IdAttribute("value_type_with_id")
},
[typeof(MetaAttribute)] = new System.Attribute[] {
new MetaAttribute()
}
};

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
};

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
};


[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
args = args ?? throw new System.ArgumentNullException(nameof(args), "Constructing ValueTypeWithId requires init args.");
return new ValueTypeWithId() {
Description = args.ContainsKey("Description") ? (string?)args["Description"] : default(string?),
Number = args.ContainsKey("Number") ? (int)args["Number"] : default(int)!
};
}
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public override bool Equals(object obj) => true;
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public override int GetHashCode() => base.GetHashCode();
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#nullable enable
namespace Chickensoft.Introspection.Generator.Tests.TestCases;

partial record class VersionedModel0 : Chickensoft.Introspection.IIntrospective {
partial record class VersionedModel0 : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#nullable enable
namespace Chickensoft.Introspection.Generator.Tests.TestCases;

partial record class VersionedModel1 : Chickensoft.Introspection.IIntrospective {
partial record class VersionedModel1 : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#nullable enable
namespace Chickensoft.Introspection.Generator.Tests.TestCases;

partial record class VersionedModel2 : Chickensoft.Introspection.IIntrospective {
partial record class VersionedModel2 : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#nullable enable
namespace Chickensoft.Introspection.Generator.Tests.TestCases;

partial record class VersionedModel3 : Chickensoft.Introspection.IIntrospective {
partial record class VersionedModel3 : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Chickensoft.Introspection.Generator.Tests.TestCases;
using Chickensoft.Introspection;
using Chickensoft.Introspection.Generator.Tests.TestUtils;

partial class BaseModel : Chickensoft.Introspection.IIntrospective {
partial class BaseModel : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma warning disable
#nullable enable
namespace Chickensoft.Introspection.Generator.Tests.TestCases;

partial record struct ValueType : Chickensoft.Introspection.IIntrospective {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.IMetatype Metatype => ((Chickensoft.Introspection.IIntrospectiveTypeMetadata)Chickensoft.Introspection.Types.Graph.GetMetadata(typeof(ValueType))).Metatype;

public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Type Type => typeof(ValueType);
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public bool HasInitProperties { get; } = true;

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Collections.Generic.IReadOnlyList<Chickensoft.Introspection.PropertyMetadata> Properties { get; } = new System.Collections.Generic.List<Chickensoft.Introspection.PropertyMetadata>() {
new Chickensoft.Introspection.PropertyMetadata(
Name: "Description",
IsInit: true,
IsRequired: false,
HasDefaultValue: false,
Getter: static (object obj) => ((ValueType)obj).Description,
Setter: null,
TypeNode: new Chickensoft.Introspection.TypeNode(
OpenType: typeof(string),
ClosedType: typeof(string),
IsNullable: true,
Arguments: System.Array.Empty<TypeNode>(),
GenericTypeGetter: static receiver => receiver.Receive<string?>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
}
),
new Chickensoft.Introspection.PropertyMetadata(
Name: "Number",
IsInit: true,
IsRequired: true,
HasDefaultValue: false,
Getter: static (object obj) => ((ValueType)obj).Number,
Setter: null,
TypeNode: new Chickensoft.Introspection.TypeNode(
OpenType: typeof(int),
ClosedType: typeof(int),
IsNullable: false,
Arguments: System.Array.Empty<TypeNode>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
}
)
};

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Attribute[]> Attributes { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(MetaAttribute)] = new System.Attribute[] {
new MetaAttribute()
}
};

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Collections.Generic.IReadOnlyList<System.Type> Mixins { get; } = new System.Collections.Generic.List<System.Type>() {
};

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public System.Collections.Generic.IReadOnlyDictionary<System.Type, System.Action<object>> MixinHandlers { get; } = new System.Collections.Generic.Dictionary<System.Type, System.Action<object>>() {
};


[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public object Construct(System.Collections.Generic.IReadOnlyDictionary<string, object?>? args = null) {
args = args ?? throw new System.ArgumentNullException(nameof(args), "Constructing ValueType requires init args.");
return new ValueType() {
Description = args.ContainsKey("Description") ? (string?)args["Description"] : default(string?),
Number = args.ContainsKey("Number") ? (int)args["Number"] : default(int)!
};
}
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public override bool Equals(object obj) => true;
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public override int GetHashCode() => base.GetHashCode();
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public partial class TypeRegistry : Chickensoft.Introspection.ITypeRegistry {
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.TraditionalNamespace.GC<,,>.GCH<,>)] = new Chickensoft.Introspection.TypeMetadata("GCH<TE, TF>"),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.TraditionalNamespace.GC<,,>.GCI<,,,>)] = new Chickensoft.Introspection.TypeMetadata("GCI<TG, TH, TI, TJ>"),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.TraditionalNamespace.GC<,,>.GCI<,,>)] = new Chickensoft.Introspection.TypeMetadata("GCI<TG, TH, TI>"),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ValueType)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("ValueType", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.ValueType>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.ValueType>(), new Chickensoft.Introspection.Generator.Tests.TestCases.ValueType.MetatypeMetadata(), 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ValueTypeWithId)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("ValueTypeWithId", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.ValueTypeWithId>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.ValueTypeWithId>(), new Chickensoft.Introspection.Generator.Tests.TestCases.ValueTypeWithId.MetatypeMetadata(), "value_type_with_id", 1),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel)] = new Chickensoft.Introspection.AbstractIdentifiableTypeMetadata("VersionedModel", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel>(), new Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel.MetatypeMetadata(), "versioned_model"),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel0)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("VersionedModel0", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel0>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel0>(), new Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel0.MetatypeMetadata(), 0),
[typeof(Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel1)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("VersionedModel1", static (r) => r.Receive<Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel1>(), static () => System.Activator.CreateInstance<Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel1>(), new Chickensoft.Introspection.Generator.Tests.TestCases.VersionedModel1.MetatypeMetadata(), 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Chickensoft.Introspection.Generator.Tests.TestCases;
partial class OuterContainer {
partial class MidContainer {
partial class AInnerContainer {
partial class ZMyModel : Chickensoft.Introspection.IIntrospective {
partial class ZMyModel : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OtherNamespace.Altogether;

using Chickensoft.Introspection;

partial class ChildBaseFullyQualified2 : Chickensoft.Introspection.IIntrospective {
partial class ChildBaseFullyQualified2 : Chickensoft.Introspection.IIntrospectiveRef {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Chickensoft.Introspection.Generator.Tests.TestCases;
using Chickensoft.Introspection.Generator.Tests.TestUtils;

partial class MyContainerClass {
partial record class MyModel : Chickensoft.Introspection.IIntrospective, Chickensoft.Introspection.IIdentifiable, IMyMixin, IMySecondMixin {
partial record class MyModel : Chickensoft.Introspection.IIntrospectiveRef, Chickensoft.Introspection.IIdentifiable, IMyMixin, IMySecondMixin {
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public Chickensoft.Introspection.MixinBlackboard MixinState { get; } = new();

Expand Down
Loading
Loading