Skip to content

Commit

Permalink
fix: support set-only properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jolexxa committed Aug 20, 2024
1 parent 11e6e62 commit 2748aed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<ItemGroup>
<ProjectReference Include="../Chickensoft.Serialization/Chickensoft.Serialization.csproj" />

<PackageReference Include="Chickensoft.Introspection" Version="1.4.0" />
<PackageReference Include="Chickensoft.Introspection.Generator" Version="1.4.0" PrivateAssets="all" OutputItemType="analyzer" />
<PackageReference Include="Chickensoft.Introspection" Version="1.5.0" />
<PackageReference Include="Chickensoft.Introspection.Generator" Version="1.5.0" PrivateAssets="all" OutputItemType="analyzer" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public partial record Person {

// Shouldn't be saved since no [Save] attribute is present.
public bool Valid { get; set; } = true;

// Shouldn't even be attempted to be saved since it cannot be read.
public string Strength { set { } }
}

public enum PetType {
Expand Down
2 changes: 1 addition & 1 deletion Chickensoft.Serialization/Chickensoft.Serialization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</PackageReference>
<PackageReference Include="Chickensoft.Collections" Version="1.8.4" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="Chickensoft.Introspection" Version="1.4.0" />
<PackageReference Include="Chickensoft.Introspection" Version="1.5.0" />
<PackageReference Include="PolyKit" Version="3.0.9" />
</ItemGroup>
</Project>
7 changes: 6 additions & 1 deletion Chickensoft.Serialization/src/SerializableTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ metadata is not IConcreteIntrospectiveTypeMetadata concreteMetadata
var properties = Graph.GetProperties(type);

foreach (var property in properties) {
if (property.Getter is not { } getter) {
// Property cannot be read, only set.
continue;
}

if (GetPropertyId(property) is not { } propertyId) {
// Only write properties marked with the [Save] attribute.
continue;
Expand All @@ -246,7 +251,7 @@ metadata is not IConcreteIntrospectiveTypeMetadata concreteMetadata
options
);

var propertyValue = property.Getter(value);
var propertyValue = getter(value);
var valueType = propertyValue?.GetType();
var propertyType = property.GenericType.ClosedType;

Expand Down

0 comments on commit 2748aed

Please sign in to comment.